mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
fix WritableArray, WritableMap nullable annotations (#23397)
Summary:
Recently, I added nullable annotations to ReadableArray, ReadableMap, WritableArray, WritableMap and subclasses to improve Kotlin developer experience. But found that I made mistake with pushArray, pushMap, pushString method of WritableArray, and putArray, putMap, putString methods of WritableMap. This PR fixes previous mistake.
Excerpt from WritableNativeArray.cpp.
```cpp
void WritableNativeArray::pushString(jstring value) {
if (value == NULL) {
pushNull();
return;
}
throwIfConsumed();
array_.push_back(wrap_alias(value)->toStdString());
}
void WritableNativeArray::pushNativeArray(WritableNativeArray* otherArray) {
if (otherArray == NULL) {
pushNull();
return;
}
throwIfConsumed();
array_.push_back(otherArray->consume());
}
void WritableNativeArray::pushNativeMap(WritableNativeMap* map) {
if (map == NULL) {
pushNull();
return;
}
throwIfConsumed();
array_.push_back(map->consume());
}
```
Excerpt from WritableNativeMap.cpp
```cpp
void WritableNativeMap::putString(std::string key, alias_ref<jstring> val) {
if (!val) {
putNull(std::move(key));
return;
}
throwIfConsumed();
map_.insert(std::move(key), val->toString());
}
void WritableNativeMap::putNativeArray(std::string key, WritableNativeArray* otherArray) {
if (!otherArray) {
putNull(std::move(key));
return;
}
throwIfConsumed();
map_.insert(key, otherArray->consume());
}
void WritableNativeMap::putNativeMap(std::string key, WritableNativeMap *otherMap) {
if (!otherMap) {
putNull(std::move(key));
return;
}
throwIfConsumed();
map_.insert(std::move(key), otherMap->consume());
}
```
[Android] [Changed] - fix nullable annotations in WritableArray, WritableMap
Pull Request resolved: https://github.com/facebook/react-native/pull/23397
Differential Revision: D14044014
Pulled By: cpojer
fbshipit-source-id: c44ea2e097e7b1156223b516aa640a181f0d4a9b
This commit is contained in:
committed by
Facebook Github Bot
parent
77300ca91c
commit
7b33d6b0b9
@@ -160,7 +160,7 @@ public class JavaOnlyArray implements ReadableArray, WritableArray {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushString(@Nonnull String value) {
|
||||
public void pushString(@Nullable String value) {
|
||||
mBackingList.add(value);
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ public class JavaOnlyArray implements ReadableArray, WritableArray {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushMap(@Nonnull WritableMap map) {
|
||||
public void pushMap(@Nullable WritableMap map) {
|
||||
mBackingList.add(map);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user