Skip to content

Commit

Permalink
Added missing constructor to WritableNativeArray (#32796)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
piaskowyk authored and facebook-github-bot committed Jan 3, 2022
1 parent e22b760 commit c68c47d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ReactAndroid/src/main/jni/react/jni/WritableNativeArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ namespace react {
WritableNativeArray::WritableNativeArray()
: HybridBase(folly::dynamic::array()) {}

WritableNativeArray::WritableNativeArray(folly::dynamic &&val)
: HybridBase(std::move(val)) {
if (!array_.isArray()) {
throw std::runtime_error("WritableNativeArray value must be an array.");
}
}

local_ref<WritableNativeArray::jhybriddata> WritableNativeArray::initHybrid(
alias_ref<jclass>) {
return makeCxxInstance();
Expand Down
2 changes: 2 additions & 0 deletions ReactAndroid/src/main/jni/react/jni/WritableNativeArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ struct WritableNativeArray
"Lcom/facebook/react/bridge/WritableNativeArray;";

WritableNativeArray();
WritableNativeArray(folly::dynamic &&val);

static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jclass>);

void pushNull();
Expand Down

0 comments on commit c68c47d

Please sign in to comment.