Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Upgrade to Nitro 0.21.0 #477

Merged
merged 4 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"react-native": "0.76.3",
"react-native-blurhash": "2.1.0",
"react-native-edge-to-edge": "1.1.3",
"react-native-nitro-modules": "0.18.2",
"react-native-nitro-modules": "0.21.0",
"react-native-reanimated": "3.16.2",
"react-native-unistyles": "workspace:*"
},
Expand Down
2 changes: 1 addition & 1 deletion expo-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"react-dom": "18.3.1",
"react-native": "0.76.6",
"react-native-edge-to-edge": "1.3.1",
"react-native-nitro-modules": "0.18.2",
"react-native-nitro-modules": "0.21.0",
"react-native-safe-area-context": "4.14.1",
"react-native-screens": "4.5.0",
"react-native-web": "0.19.13"
Expand Down
10 changes: 5 additions & 5 deletions expo-example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4421,7 +4421,7 @@ __metadata:
react-dom: 18.3.1
react-native: 0.76.6
react-native-edge-to-edge: 1.3.1
react-native-nitro-modules: 0.18.2
react-native-nitro-modules: 0.21.0
react-native-safe-area-context: 4.14.1
react-native-screens: 4.5.0
react-native-web: 0.19.13
Expand Down Expand Up @@ -7466,13 +7466,13 @@ __metadata:
languageName: node
linkType: hard

"react-native-nitro-modules@npm:0.18.2":
version: 0.18.2
resolution: "react-native-nitro-modules@npm:0.18.2"
"react-native-nitro-modules@npm:0.21.0":
version: 0.21.0
resolution: "react-native-nitro-modules@npm:0.21.0"
peerDependencies:
react: "*"
react-native: "*"
checksum: 2ab3804e5a1129a63afe4a6581d7ca880a8846f7a7ff87a0cd835efad7efbde897dd452aab406074952f7ad7fc1ec0b437105cfef731c40ab158353befc8bfaa
checksum: ef0f88d2fb98aad489b10a661874e20cfc73c5beaa7d503ad3bcbbaff20ee0db200282f515bb374154a4f1895ca1ebe6e66545dae76377e256d6d3e8c6de220b
languageName: node
linkType: hard

Expand Down
8 changes: 2 additions & 6 deletions ios/NativePlatform+ios.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ class NativeIOSPlatform: HybridNativePlatformSpec {

var dependencyListeners: Array<CxxDependencyListener> = []
var imeListeners: Array<CxxImeListener> = []
var hybridContext = margelo.nitro.HybridContext()
var memorySize: Int {
return getSizeOf(self)
}

init() {
self.miniRuntime = self.buildMiniRuntime()
Expand Down Expand Up @@ -187,15 +183,15 @@ class NativeIOSPlatform: HybridNativePlatformSpec {
return getContentSizeCategoryFn()
}
}

func getMainWindow() -> UIWindow? {
guard let mainWindow = UIApplication.shared.connectedScenes
.compactMap({ $0 as? UIWindowScene })
.flatMap({ $0.windows })
.first(where: { $0.isKeyWindow }) else {
return nil
}

return mainWindow
}

Expand Down
3 changes: 2 additions & 1 deletion nitrogen/generated/android/c++/JColorScheme.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// JColorScheme.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once
Expand All @@ -26,6 +26,7 @@ namespace margelo::nitro::unistyles {
* Convert this Java/Kotlin-based enum to the C++ enum ColorScheme.
*/
[[maybe_unused]]
[[nodiscard]]
ColorScheme toCpp() const {
static const auto clazz = javaClassStatic();
static const auto fieldOrdinal = clazz->getField<int>("_ordinal");
Expand Down
3 changes: 2 additions & 1 deletion nitrogen/generated/android/c++/JDimensions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// JDimensions.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once
Expand All @@ -28,6 +28,7 @@ namespace margelo::nitro::unistyles {
* Convert this Java/Kotlin-based struct to the C++ struct Dimensions by copying all values to C++.
*/
[[maybe_unused]]
[[nodiscard]]
Dimensions toCpp() const {
static const auto clazz = javaClassStatic();
static const auto fieldWidth = clazz->getField<double>("width");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// JFunc_void_UnistylesNativeMiniRuntime.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once
Expand All @@ -26,28 +26,54 @@ namespace margelo::nitro::unistyles {
using namespace facebook;

/**
* C++ representation of the callback Func_void_UnistylesNativeMiniRuntime.
* This is a Kotlin `(miniRuntime: UnistylesNativeMiniRuntime) -> Unit`, backed by a `std::function<...>`.
* Represents the Java/Kotlin callback `(miniRuntime: UnistylesNativeMiniRuntime) -> Unit`.
* This can be passed around between C++ and Java/Kotlin.
*/
struct JFunc_void_UnistylesNativeMiniRuntime final: public jni::HybridClass<JFunc_void_UnistylesNativeMiniRuntime> {
struct JFunc_void_UnistylesNativeMiniRuntime: public jni::JavaClass<JFunc_void_UnistylesNativeMiniRuntime> {
public:
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime;";

public:
/**
* Invokes the function this `JFunc_void_UnistylesNativeMiniRuntime` instance holds through JNI.
*/
void invoke(const UnistylesNativeMiniRuntime& miniRuntime) const {
static const auto method = getClass()->getMethod<void(jni::alias_ref<JUnistylesNativeMiniRuntime> /* miniRuntime */)>("invoke");
method(self(), JUnistylesNativeMiniRuntime::fromCpp(miniRuntime));
}
};

/**
* An implementation of Func_void_UnistylesNativeMiniRuntime that is backed by a C++ implementation (using `std::function<...>`)
*/
struct JFunc_void_UnistylesNativeMiniRuntime_cxx final: public jni::HybridClass<JFunc_void_UnistylesNativeMiniRuntime_cxx, JFunc_void_UnistylesNativeMiniRuntime> {
public:
static jni::local_ref<JFunc_void_UnistylesNativeMiniRuntime::javaobject> fromCpp(const std::function<void(const UnistylesNativeMiniRuntime& /* miniRuntime */)>& func) {
return JFunc_void_UnistylesNativeMiniRuntime::newObjectCxxArgs(func);
return JFunc_void_UnistylesNativeMiniRuntime_cxx::newObjectCxxArgs(func);
}

public:
void call(jni::alias_ref<JUnistylesNativeMiniRuntime> miniRuntime) {
return _func(miniRuntime->toCpp());
/**
* Invokes the C++ `std::function<...>` this `JFunc_void_UnistylesNativeMiniRuntime_cxx` instance holds.
*/
void invoke_cxx(jni::alias_ref<JUnistylesNativeMiniRuntime> miniRuntime) {
_func(miniRuntime->toCpp());
}

public:
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime;";
[[nodiscard]]
inline const std::function<void(const UnistylesNativeMiniRuntime& /* miniRuntime */)>& getFunction() const {
return _func;
}

public:
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime_cxx;";
static void registerNatives() {
registerHybrid({makeNativeMethod("call", JFunc_void_UnistylesNativeMiniRuntime::call)});
registerHybrid({makeNativeMethod("invoke", JFunc_void_UnistylesNativeMiniRuntime_cxx::invoke_cxx)});
}

private:
explicit JFunc_void_UnistylesNativeMiniRuntime(const std::function<void(const UnistylesNativeMiniRuntime& /* miniRuntime */)>& func): _func(func) { }
explicit JFunc_void_UnistylesNativeMiniRuntime_cxx(const std::function<void(const UnistylesNativeMiniRuntime& /* miniRuntime */)>& func): _func(func) { }

private:
friend HybridBase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once
Expand All @@ -29,37 +29,71 @@ namespace margelo::nitro::unistyles {
using namespace facebook;

/**
* C++ representation of the callback Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.
* This is a Kotlin `(dependencies: Array<UnistyleDependency>, miniRuntime: UnistylesNativeMiniRuntime) -> Unit`, backed by a `std::function<...>`.
* Represents the Java/Kotlin callback `(dependencies: Array<UnistyleDependency>, miniRuntime: UnistylesNativeMiniRuntime) -> Unit`.
* This can be passed around between C++ and Java/Kotlin.
*/
struct JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime final: public jni::HybridClass<JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime> {
struct JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime: public jni::JavaClass<JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime> {
public:
static jni::local_ref<JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime::javaobject> fromCpp(const std::function<void(const std::vector<UnistyleDependency>& /* dependencies */, const UnistylesNativeMiniRuntime& /* miniRuntime */)>& func) {
return JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime::newObjectCxxArgs(func);
}
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime;";

public:
void call(jni::alias_ref<jni::JArrayClass<JUnistyleDependency>> dependencies, jni::alias_ref<JUnistylesNativeMiniRuntime> miniRuntime) {
return _func([&]() {
size_t __size = dependencies->size();
std::vector<UnistyleDependency> __vector;
__vector.reserve(__size);
/**
* Invokes the function this `JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime` instance holds through JNI.
*/
void invoke(const std::vector<UnistyleDependency>& dependencies, const UnistylesNativeMiniRuntime& miniRuntime) const {
static const auto method = getClass()->getMethod<void(jni::alias_ref<jni::JArrayClass<JUnistyleDependency>> /* dependencies */, jni::alias_ref<JUnistylesNativeMiniRuntime> /* miniRuntime */)>("invoke");
method(self(), [&]() {
size_t __size = dependencies.size();
jni::local_ref<jni::JArrayClass<JUnistyleDependency>> __array = jni::JArrayClass<JUnistyleDependency>::newArray(__size);
for (size_t __i = 0; __i < __size; __i++) {
auto __element = dependencies->getElement(__i);
__vector.push_back(__element->toCpp());
const auto& __element = dependencies[__i];
__array->setElement(__i, *JUnistyleDependency::fromCpp(__element));
}
return __vector;
}(), miniRuntime->toCpp());
return __array;
}(), JUnistylesNativeMiniRuntime::fromCpp(miniRuntime));
}
};

/**
* An implementation of Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime that is backed by a C++ implementation (using `std::function<...>`)
*/
struct JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime_cxx final: public jni::HybridClass<JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime_cxx, JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime> {
public:
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime;";
static jni::local_ref<JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime::javaobject> fromCpp(const std::function<void(const std::vector<UnistyleDependency>& /* dependencies */, const UnistylesNativeMiniRuntime& /* miniRuntime */)>& func) {
return JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime_cxx::newObjectCxxArgs(func);
}

public:
/**
* Invokes the C++ `std::function<...>` this `JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime_cxx` instance holds.
*/
void invoke_cxx(jni::alias_ref<jni::JArrayClass<JUnistyleDependency>> dependencies, jni::alias_ref<JUnistylesNativeMiniRuntime> miniRuntime) {
_func([&]() {
size_t __size = dependencies->size();
std::vector<UnistyleDependency> __vector;
__vector.reserve(__size);
for (size_t __i = 0; __i < __size; __i++) {
auto __element = dependencies->getElement(__i);
__vector.push_back(__element->toCpp());
}
return __vector;
}(), miniRuntime->toCpp());
}

public:
[[nodiscard]]
inline const std::function<void(const std::vector<UnistyleDependency>& /* dependencies */, const UnistylesNativeMiniRuntime& /* miniRuntime */)>& getFunction() const {
return _func;
}

public:
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime_cxx;";
static void registerNatives() {
registerHybrid({makeNativeMethod("call", JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime::call)});
registerHybrid({makeNativeMethod("invoke", JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime_cxx::invoke_cxx)});
}

private:
explicit JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime(const std::function<void(const std::vector<UnistyleDependency>& /* dependencies */, const UnistylesNativeMiniRuntime& /* miniRuntime */)>& func): _func(func) { }
explicit JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime_cxx(const std::function<void(const std::vector<UnistyleDependency>& /* dependencies */, const UnistylesNativeMiniRuntime& /* miniRuntime */)>& func): _func(func) { }

private:
friend HybridBase;
Expand Down
10 changes: 5 additions & 5 deletions nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// JHybridNativePlatformSpec.cpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#include "JHybridNativePlatformSpec.hpp"
Expand Down Expand Up @@ -131,12 +131,12 @@ namespace margelo::nitro::unistyles {
return __result->toCpp();
}
void JHybridNativePlatformSpec::registerPlatformListener(const std::function<void(const std::vector<UnistyleDependency>& /* dependencies */, const UnistylesNativeMiniRuntime& /* miniRuntime */)>& callback) {
static const auto method = _javaPart->getClass()->getMethod<void(jni::alias_ref<JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime::javaobject> /* callback */)>("registerPlatformListener");
method(_javaPart, JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime::fromCpp(callback));
static const auto method = _javaPart->getClass()->getMethod<void(jni::alias_ref<JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime::javaobject> /* callback */)>("registerPlatformListener_cxx");
method(_javaPart, JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime_cxx::fromCpp(callback));
}
void JHybridNativePlatformSpec::registerImeListener(const std::function<void(const UnistylesNativeMiniRuntime& /* miniRuntime */)>& callback) {
static const auto method = _javaPart->getClass()->getMethod<void(jni::alias_ref<JFunc_void_UnistylesNativeMiniRuntime::javaobject> /* callback */)>("registerImeListener");
method(_javaPart, JFunc_void_UnistylesNativeMiniRuntime::fromCpp(callback));
static const auto method = _javaPart->getClass()->getMethod<void(jni::alias_ref<JFunc_void_UnistylesNativeMiniRuntime::javaobject> /* callback */)>("registerImeListener_cxx");
method(_javaPart, JFunc_void_UnistylesNativeMiniRuntime_cxx::fromCpp(callback));
}
void JHybridNativePlatformSpec::unregisterPlatformListeners() {
static const auto method = _javaPart->getClass()->getMethod<void()>("unregisterPlatformListeners");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// HybridNativePlatformSpec.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once
Expand Down
3 changes: 2 additions & 1 deletion nitrogen/generated/android/c++/JInsets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// JInsets.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once
Expand All @@ -28,6 +28,7 @@ namespace margelo::nitro::unistyles {
* Convert this Java/Kotlin-based struct to the C++ struct Insets by copying all values to C++.
*/
[[maybe_unused]]
[[nodiscard]]
Insets toCpp() const {
static const auto clazz = javaClassStatic();
static const auto fieldTop = clazz->getField<double>("top");
Expand Down
3 changes: 2 additions & 1 deletion nitrogen/generated/android/c++/JOrientation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// JOrientation.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once
Expand All @@ -26,6 +26,7 @@ namespace margelo::nitro::unistyles {
* Convert this Java/Kotlin-based enum to the C++ enum Orientation.
*/
[[maybe_unused]]
[[nodiscard]]
Orientation toCpp() const {
static const auto clazz = javaClassStatic();
static const auto fieldOrdinal = clazz->getField<int>("_ordinal");
Expand Down
3 changes: 2 additions & 1 deletion nitrogen/generated/android/c++/JUnistyleDependency.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// JUnistyleDependency.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once
Expand All @@ -26,6 +26,7 @@ namespace margelo::nitro::unistyles {
* Convert this Java/Kotlin-based enum to the C++ enum UnistyleDependency.
*/
[[maybe_unused]]
[[nodiscard]]
UnistyleDependency toCpp() const {
static const auto clazz = javaClassStatic();
static const auto fieldOrdinal = clazz->getField<int>("_ordinal");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// JUnistylesNativeMiniRuntime.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once
Expand Down Expand Up @@ -34,6 +34,7 @@ namespace margelo::nitro::unistyles {
* Convert this Java/Kotlin-based struct to the C++ struct UnistylesNativeMiniRuntime by copying all values to C++.
*/
[[maybe_unused]]
[[nodiscard]]
UnistylesNativeMiniRuntime toCpp() const {
static const auto clazz = javaClassStatic();
static const auto fieldColorScheme = clazz->getField<JColorScheme>("colorScheme");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// ColorScheme.kt
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
/// Copyright © 2025 Marc Rousavy @ Margelo
///

package com.margelo.nitro.unistyles
Expand Down
Loading