Skip to content

Commit c67ae56

Browse files
committed
feat: upgrade nitro to v0.18
1 parent b52b49e commit c67ae56

33 files changed

+281
-1443
lines changed

example/ios/Podfile.lock

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,21 @@ PODS:
2929
- hermes-engine (0.76.0):
3030
- hermes-engine/Pre-built (= 0.76.0)
3131
- hermes-engine/Pre-built (0.76.0)
32-
- NitroModules (0.15.0):
32+
- NitroModules (0.18.1):
3333
- DoubleConversion
3434
- glog
3535
- hermes-engine
3636
- RCT-Folly (= 2024.01.01.00)
3737
- RCTRequired
3838
- RCTTypeSafety
39+
- React-callinvoker
3940
- React-Core
4041
- React-debug
4142
- React-Fabric
4243
- React-featureflags
4344
- React-graphics
4445
- React-ImageManager
46+
- React-jsi
4547
- React-NativeModulesApple
4648
- React-RCTFabric
4749
- React-rendererdebug
@@ -1769,7 +1771,7 @@ SPEC CHECKSUMS:
17691771
fmt: 10c6e61f4be25dc963c36bd73fc7b1705fe975be
17701772
glog: 08b301085f15bcbb6ff8632a8ebaf239aae04e6a
17711773
hermes-engine: 9de51d2f67336348a6cd5b686330e436d1dbd522
1772-
NitroModules: 11c64b7b1c3fd5c83762c4946c4c4c20951d7b86
1774+
NitroModules: 1301dc53a33ca73ada1479a3dda1141032d8e597
17731775
RCT-Folly: bf5c0376ffe4dd2cf438dcf86db385df9fdce648
17741776
RCTDeprecation: 4c2c4a088b6f0ccfcbd53c9d5614b0238ad57909
17751777
RCTRequired: 2d8a683a7848bc0baf5883f0792c1ac43f6267b5

example/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"cli-table3": "^0.6.5",
1313
"react": "18.3.1",
1414
"react-native": "0.76.0",
15-
"react-native-nitro-modules": "^0.15.0"
15+
"react-native-nitro-modules": "^0.18.0"
1616
},
1717
"devDependencies": {
1818
"@babel/core": "^7.20.0",

package-lock.json

+33-1,258
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-native-fast-io/nitrogen/generated/android/FastIOOnLoad.cpp

+11-45
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "JFunc_void_std__shared_ptr_ArrayBuffer_.hpp"
2424
#include "JHybridWebSocketManagerSpec.hpp"
2525
#include <NitroModules/JNISharedPtr.hpp>
26+
#include <NitroModules/DefaultConstructableObject.hpp>
2627
#include "HybridCompressorFactory.hpp"
2728

2829
namespace margelo::nitro::fastio {
@@ -52,63 +53,35 @@ int initialize(JavaVM* vm) {
5253
HybridObjectRegistry::registerHybridObjectConstructor(
5354
"WebSocketManager",
5455
[]() -> std::shared_ptr<HybridObject> {
55-
static auto javaClass = jni::findClassStatic("com/margelo/nitro/fastio/HybridWebSocketManager");
56-
static auto defaultConstructor = javaClass->getConstructor<JHybridWebSocketManagerSpec::javaobject()>();
57-
58-
auto instance = javaClass->newObject(defaultConstructor);
59-
#ifdef NITRO_DEBUG
60-
if (instance == nullptr) [[unlikely]] {
61-
throw std::runtime_error("Failed to create an instance of \"JHybridWebSocketManagerSpec\" - the constructor returned null!");
62-
}
63-
#endif
56+
static DefaultConstructableObject<JHybridWebSocketManagerSpec::javaobject> object("com/margelo/nitro/fastio/HybridWebSocketManager");
57+
auto instance = object.create();
6458
auto globalRef = jni::make_global(instance);
6559
return JNISharedPtr::make_shared_from_jni<JHybridWebSocketManagerSpec>(globalRef);
6660
}
6761
);
6862
HybridObjectRegistry::registerHybridObjectConstructor(
6963
"FileSystem",
7064
[]() -> std::shared_ptr<HybridObject> {
71-
static auto javaClass = jni::findClassStatic("com/margelo/nitro/fastio/HybridFileSystem");
72-
static auto defaultConstructor = javaClass->getConstructor<JHybridFileSystemSpec::javaobject()>();
73-
74-
auto instance = javaClass->newObject(defaultConstructor);
75-
#ifdef NITRO_DEBUG
76-
if (instance == nullptr) [[unlikely]] {
77-
throw std::runtime_error("Failed to create an instance of \"JHybridFileSystemSpec\" - the constructor returned null!");
78-
}
79-
#endif
65+
static DefaultConstructableObject<JHybridFileSystemSpec::javaobject> object("com/margelo/nitro/fastio/HybridFileSystem");
66+
auto instance = object.create();
8067
auto globalRef = jni::make_global(instance);
8168
return JNISharedPtr::make_shared_from_jni<JHybridFileSystemSpec>(globalRef);
8269
}
8370
);
8471
HybridObjectRegistry::registerHybridObjectConstructor(
8572
"Network",
8673
[]() -> std::shared_ptr<HybridObject> {
87-
static auto javaClass = jni::findClassStatic("com/margelo/nitro/fastio/HybridNetwork");
88-
static auto defaultConstructor = javaClass->getConstructor<JHybridNetworkSpec::javaobject()>();
89-
90-
auto instance = javaClass->newObject(defaultConstructor);
91-
#ifdef NITRO_DEBUG
92-
if (instance == nullptr) [[unlikely]] {
93-
throw std::runtime_error("Failed to create an instance of \"JHybridNetworkSpec\" - the constructor returned null!");
94-
}
95-
#endif
74+
static DefaultConstructableObject<JHybridNetworkSpec::javaobject> object("com/margelo/nitro/fastio/HybridNetwork");
75+
auto instance = object.create();
9676
auto globalRef = jni::make_global(instance);
9777
return JNISharedPtr::make_shared_from_jni<JHybridNetworkSpec>(globalRef);
9878
}
9979
);
10080
HybridObjectRegistry::registerHybridObjectConstructor(
10181
"DuplexStream",
10282
[]() -> std::shared_ptr<HybridObject> {
103-
static auto javaClass = jni::findClassStatic("com/margelo/nitro/fastio/HybridDuplexStream");
104-
static auto defaultConstructor = javaClass->getConstructor<JHybridDuplexStreamSpec::javaobject()>();
105-
106-
auto instance = javaClass->newObject(defaultConstructor);
107-
#ifdef NITRO_DEBUG
108-
if (instance == nullptr) [[unlikely]] {
109-
throw std::runtime_error("Failed to create an instance of \"JHybridDuplexStreamSpec\" - the constructor returned null!");
110-
}
111-
#endif
83+
static DefaultConstructableObject<JHybridDuplexStreamSpec::javaobject> object("com/margelo/nitro/fastio/HybridDuplexStream");
84+
auto instance = object.create();
11285
auto globalRef = jni::make_global(instance);
11386
return JNISharedPtr::make_shared_from_jni<JHybridDuplexStreamSpec>(globalRef);
11487
}
@@ -125,15 +98,8 @@ int initialize(JavaVM* vm) {
12598
HybridObjectRegistry::registerHybridObjectConstructor(
12699
"StreamFactory",
127100
[]() -> std::shared_ptr<HybridObject> {
128-
static auto javaClass = jni::findClassStatic("com/margelo/nitro/fastio/HybridStreamFactory");
129-
static auto defaultConstructor = javaClass->getConstructor<JHybridStreamFactorySpec::javaobject()>();
130-
131-
auto instance = javaClass->newObject(defaultConstructor);
132-
#ifdef NITRO_DEBUG
133-
if (instance == nullptr) [[unlikely]] {
134-
throw std::runtime_error("Failed to create an instance of \"JHybridStreamFactorySpec\" - the constructor returned null!");
135-
}
136-
#endif
101+
static DefaultConstructableObject<JHybridStreamFactorySpec::javaobject> object("com/margelo/nitro/fastio/HybridStreamFactory");
102+
auto instance = object.create();
137103
auto globalRef = jni::make_global(instance);
138104
return JNISharedPtr::make_shared_from_jni<JHybridStreamFactorySpec>(globalRef);
139105
}

packages/react-native-fast-io/nitrogen/generated/android/c++/JFunc_void_std__shared_ptr_ArrayBuffer_.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <functional>
1414
#include <NitroModules/ArrayBuffer.hpp>
1515
#include <NitroModules/JArrayBuffer.hpp>
16+
#include <NitroModules/JUnit.hpp>
1617

1718
namespace margelo::nitro::fastio {
1819

packages/react-native-fast-io/nitrogen/generated/android/c++/JHybridFileSystemSpec.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace margelo::nitro::fastio { struct NativeFilePickerOptions; }
1717
#include "Metadata.hpp"
1818
#include "JMetadata.hpp"
1919
#include <string>
20-
#include <future>
20+
#include <NitroModules/Promise.hpp>
2121
#include <vector>
2222
#include <NitroModules/JPromise.hpp>
2323
#include "WellKnownDirectory.hpp"
@@ -57,14 +57,14 @@ namespace margelo::nitro::fastio {
5757
auto __result = method(_javaPart, JWellKnownDirectory::fromCpp(directory));
5858
return __result->toStdString();
5959
}
60-
std::future<std::vector<std::string>> JHybridFileSystemSpec::showOpenFilePicker(const std::optional<NativeFilePickerOptions>& options) {
60+
std::shared_ptr<Promise<std::vector<std::string>>> JHybridFileSystemSpec::showOpenFilePicker(const std::optional<NativeFilePickerOptions>& options) {
6161
static const auto method = _javaPart->getClass()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<JNativeFilePickerOptions> /* options */)>("showOpenFilePicker");
6262
auto __result = method(_javaPart, options.has_value() ? JNativeFilePickerOptions::fromCpp(options.value()) : nullptr);
6363
return [&]() {
64-
auto __promise = std::make_shared<std::promise<std::vector<std::string>>>();
64+
auto __promise = Promise<std::vector<std::string>>::create();
6565
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
6666
auto __result = jni::static_ref_cast<jni::JArrayClass<jni::JString>>(__boxedResult);
67-
__promise->set_value([&]() {
67+
__promise->resolve([&]() {
6868
size_t __size = __result->size();
6969
std::vector<std::string> __vector;
7070
__vector.reserve(__size);
@@ -75,11 +75,11 @@ namespace margelo::nitro::fastio {
7575
return __vector;
7676
}());
7777
});
78-
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JString>& __message) {
79-
std::runtime_error __error(__message->toStdString());
80-
__promise->set_exception(std::make_exception_ptr(__error));
78+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
79+
jni::JniException __jniError(__throwable);
80+
__promise->reject(std::make_exception_ptr(__jniError));
8181
});
82-
return __promise->get_future();
82+
return __promise;
8383
}();
8484
}
8585

packages/react-native-fast-io/nitrogen/generated/android/c++/JHybridFileSystemSpec.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace margelo::nitro::fastio {
5353
// Methods
5454
Metadata getMetadata(const std::string& path) override;
5555
std::string getWellKnownDirectoryPath(WellKnownDirectory directory) override;
56-
std::future<std::vector<std::string>> showOpenFilePicker(const std::optional<NativeFilePickerOptions>& options) override;
56+
std::shared_ptr<Promise<std::vector<std::string>>> showOpenFilePicker(const std::optional<NativeFilePickerOptions>& options) override;
5757

5858
private:
5959
friend HybridBase;

packages/react-native-fast-io/nitrogen/generated/android/c++/JHybridInputStreamSpec.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
// Forward declaration of `ArrayBuffer` to properly resolve imports.
1111
namespace NitroModules { class ArrayBuffer; }
1212

13-
#include <future>
13+
#include <NitroModules/Promise.hpp>
1414
#include <NitroModules/ArrayBuffer.hpp>
1515
#include <NitroModules/JPromise.hpp>
1616
#include <NitroModules/JArrayBuffer.hpp>
17+
#include <NitroModules/JUnit.hpp>
1718

1819
namespace margelo::nitro::fastio {
1920

@@ -36,20 +37,20 @@ namespace margelo::nitro::fastio {
3637

3738

3839
// Methods
39-
std::future<std::shared_ptr<ArrayBuffer>> JHybridInputStreamSpec::read() {
40+
std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>> JHybridInputStreamSpec::read() {
4041
static const auto method = _javaPart->getClass()->getMethod<jni::local_ref<JPromise::javaobject>()>("read");
4142
auto __result = method(_javaPart);
4243
return [&]() {
43-
auto __promise = std::make_shared<std::promise<std::shared_ptr<ArrayBuffer>>>();
44+
auto __promise = Promise<std::shared_ptr<ArrayBuffer>>::create();
4445
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
4546
auto __result = jni::static_ref_cast<JArrayBuffer::javaobject>(__boxedResult);
46-
__promise->set_value(__result->cthis()->getArrayBuffer());
47+
__promise->resolve(__result->cthis()->getArrayBuffer());
4748
});
48-
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JString>& __message) {
49-
std::runtime_error __error(__message->toStdString());
50-
__promise->set_exception(std::make_exception_ptr(__error));
49+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
50+
jni::JniException __jniError(__throwable);
51+
__promise->reject(std::make_exception_ptr(__jniError));
5152
});
52-
return __promise->get_future();
53+
return __promise;
5354
}();
5455
}
5556
void JHybridInputStreamSpec::open() {

packages/react-native-fast-io/nitrogen/generated/android/c++/JHybridInputStreamSpec.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ namespace margelo::nitro::fastio {
5151

5252
public:
5353
// Methods
54-
std::future<std::shared_ptr<ArrayBuffer>> read() override;
54+
std::shared_ptr<Promise<std::shared_ptr<ArrayBuffer>>> read() override;
5555
void open() override;
5656
void close() override;
5757

packages/react-native-fast-io/nitrogen/generated/android/c++/JHybridNetworkSpec.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace margelo::nitro::fastio { enum class RequestMethod; }
1414
// Forward declaration of `HybridInputStreamSpec` to properly resolve imports.
1515
namespace margelo::nitro::fastio { class HybridInputStreamSpec; }
1616

17-
#include <future>
17+
#include <NitroModules/Promise.hpp>
1818
#include <NitroModules/JPromise.hpp>
1919
#include "RequestOptions.hpp"
2020
#include "JRequestOptions.hpp"
@@ -48,19 +48,19 @@ namespace margelo::nitro::fastio {
4848

4949

5050
// Methods
51-
std::future<void> JHybridNetworkSpec::request(const RequestOptions& opts) {
51+
std::shared_ptr<Promise<void>> JHybridNetworkSpec::request(const RequestOptions& opts) {
5252
static const auto method = _javaPart->getClass()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<JRequestOptions> /* opts */)>("request");
5353
auto __result = method(_javaPart, JRequestOptions::fromCpp(opts));
5454
return [&]() {
55-
auto __promise = std::make_shared<std::promise<void>>();
55+
auto __promise = Promise<void>::create();
5656
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
57-
__promise->set_value();
57+
__promise->resolve();
5858
});
59-
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JString>& __message) {
60-
std::runtime_error __error(__message->toStdString());
61-
__promise->set_exception(std::make_exception_ptr(__error));
59+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
60+
jni::JniException __jniError(__throwable);
61+
__promise->reject(std::make_exception_ptr(__jniError));
6262
});
63-
return __promise->get_future();
63+
return __promise;
6464
}();
6565
}
6666

packages/react-native-fast-io/nitrogen/generated/android/c++/JHybridNetworkSpec.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ namespace margelo::nitro::fastio {
5151

5252
public:
5353
// Methods
54-
std::future<void> request(const RequestOptions& opts) override;
54+
std::shared_ptr<Promise<void>> request(const RequestOptions& opts) override;
5555

5656
private:
5757
friend HybridBase;

packages/react-native-fast-io/nitrogen/generated/android/c++/JHybridOutputStreamSpec.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
// Forward declaration of `ArrayBuffer` to properly resolve imports.
1111
namespace NitroModules { class ArrayBuffer; }
1212

13-
#include <future>
13+
#include <NitroModules/Promise.hpp>
1414
#include <NitroModules/JPromise.hpp>
1515
#include <NitroModules/ArrayBuffer.hpp>
1616
#include <NitroModules/JArrayBuffer.hpp>
17+
#include <NitroModules/JUnit.hpp>
1718

1819
namespace margelo::nitro::fastio {
1920

@@ -36,19 +37,19 @@ namespace margelo::nitro::fastio {
3637

3738

3839
// Methods
39-
std::future<void> JHybridOutputStreamSpec::write(const std::shared_ptr<ArrayBuffer>& buffer) {
40+
std::shared_ptr<Promise<void>> JHybridOutputStreamSpec::write(const std::shared_ptr<ArrayBuffer>& buffer) {
4041
static const auto method = _javaPart->getClass()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<JArrayBuffer::javaobject> /* buffer */)>("write");
4142
auto __result = method(_javaPart, JArrayBuffer::wrap(buffer));
4243
return [&]() {
43-
auto __promise = std::make_shared<std::promise<void>>();
44+
auto __promise = Promise<void>::create();
4445
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
45-
__promise->set_value();
46+
__promise->resolve();
4647
});
47-
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JString>& __message) {
48-
std::runtime_error __error(__message->toStdString());
49-
__promise->set_exception(std::make_exception_ptr(__error));
48+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
49+
jni::JniException __jniError(__throwable);
50+
__promise->reject(std::make_exception_ptr(__jniError));
5051
});
51-
return __promise->get_future();
52+
return __promise;
5253
}();
5354
}
5455
void JHybridOutputStreamSpec::open() {

packages/react-native-fast-io/nitrogen/generated/android/c++/JHybridOutputStreamSpec.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ namespace margelo::nitro::fastio {
5151

5252
public:
5353
// Methods
54-
std::future<void> write(const std::shared_ptr<ArrayBuffer>& buffer) override;
54+
std::shared_ptr<Promise<void>> write(const std::shared_ptr<ArrayBuffer>& buffer) override;
5555
void open() override;
5656
void close() override;
5757

packages/react-native-fast-io/nitrogen/generated/android/c++/JHybridWebSocketSpec.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace NitroModules { class ArrayBuffer; }
1313
#include <string>
1414
#include <NitroModules/ArrayBuffer.hpp>
1515
#include <NitroModules/JArrayBuffer.hpp>
16+
#include <NitroModules/JUnit.hpp>
1617
#include <functional>
1718
#include "JFunc_void_std__string.hpp"
1819
#include "JFunc_void_double_std__string.hpp"

packages/react-native-fast-io/nitrogen/generated/android/c++/JRequestMethod.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace margelo::nitro::fastio {
2828
[[maybe_unused]]
2929
RequestMethod toCpp() const {
3030
static const auto clazz = javaClassStatic();
31-
static const auto fieldOrdinal = clazz->getField<int>("ordinal");
31+
static const auto fieldOrdinal = clazz->getField<int>("_ordinal");
3232
int ordinal = this->getFieldValue(fieldOrdinal);
3333
return static_cast<RequestMethod>(ordinal);
3434
}

packages/react-native-fast-io/nitrogen/generated/android/c++/JWellKnownDirectory.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace margelo::nitro::fastio {
2828
[[maybe_unused]]
2929
WellKnownDirectory toCpp() const {
3030
static const auto clazz = javaClassStatic();
31-
static const auto fieldOrdinal = clazz->getField<int>("ordinal");
31+
static const auto fieldOrdinal = clazz->getField<int>("_ordinal");
3232
int ordinal = this->getFieldValue(fieldOrdinal);
3333
return static_cast<WellKnownDirectory>(ordinal);
3434
}

packages/react-native-fast-io/nitrogen/generated/android/kotlin/com/margelo/nitro/fastio/RequestMethod.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@ import com.facebook.proguard.annotations.DoNotStrip
1717
@Keep
1818
enum class RequestMethod {
1919
POST,
20-
GET
20+
GET;
21+
22+
@DoNotStrip
23+
@Keep
24+
private val _ordinal = ordinal
2125
}

packages/react-native-fast-io/nitrogen/generated/android/kotlin/com/margelo/nitro/fastio/WellKnownDirectory.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,9 @@ enum class WellKnownDirectory {
2121
DOWNLOADS,
2222
MUSIC,
2323
PICTURES,
24-
VIDEOS
24+
VIDEOS;
25+
26+
@DoNotStrip
27+
@Keep
28+
private val _ordinal = ordinal
2529
}

0 commit comments

Comments
 (0)