Skip to content

Commit c68c47d

Browse files
piaskowykfacebook-github-bot
authored andcommitted
Added missing constructor to WritableNativeArray (#32796)
Summary: `WritableNativeMap` has two constructors: ```c++ WritableNativeMap(); WritableNativeMap(folly::dynamic &&val); ``` but `WritableNativeMap` has only one constructor: ```c++ WritableNativeMap(); ``` Without a second constructor, I am not able to create `WritableNativeMap` from the existing array. I added this second constructor because I need it for `react-native-reanimated`. ## Changelog [Android] [Added] - Added missing constructor to WritableNativeArray Pull Request resolved: #32796 Test Plan: ```c++ std::shared_ptr<jsi::Runtime> rt = facebook::hermes::makeHermesRuntime(); jsi::Value value; WritableNativeMap::newObjectCxxArgs(jsi::dynamicFromValue(*rt.get(), value)); ``` Reviewed By: cortinico Differential Revision: D33285316 Pulled By: lunaleaps fbshipit-source-id: 1bbd816892f34ae6fef747066893fe3b803c088d
1 parent e22b760 commit c68c47d

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

ReactAndroid/src/main/jni/react/jni/WritableNativeArray.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ namespace react {
1717
WritableNativeArray::WritableNativeArray()
1818
: HybridBase(folly::dynamic::array()) {}
1919

20+
WritableNativeArray::WritableNativeArray(folly::dynamic &&val)
21+
: HybridBase(std::move(val)) {
22+
if (!array_.isArray()) {
23+
throw std::runtime_error("WritableNativeArray value must be an array.");
24+
}
25+
}
26+
2027
local_ref<WritableNativeArray::jhybriddata> WritableNativeArray::initHybrid(
2128
alias_ref<jclass>) {
2229
return makeCxxInstance();

ReactAndroid/src/main/jni/react/jni/WritableNativeArray.h

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ struct WritableNativeArray
2929
"Lcom/facebook/react/bridge/WritableNativeArray;";
3030

3131
WritableNativeArray();
32+
WritableNativeArray(folly::dynamic &&val);
33+
3234
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jclass>);
3335

3436
void pushNull();

0 commit comments

Comments
 (0)