mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
iOS: undefined prop in an object shouldn't become [NSNull null] in the dictionary
Summary: [iOS] [Fixed] - The existing logic defaults `undefined` & `null` in JS to be `[NSNull null]` when converting JS object to `NSDictionary`. Let's not insert the prop to the dictionary if it's `undefined`. Reviewed By: blairvanderhoof Differential Revision: D14571128 fbshipit-source-id: e03c713b055672b0a001d3305d694912ee36ab36
This commit is contained in:
committed by
Facebook Github Bot
parent
dd9959ab0e
commit
3e8d2a18d7
@@ -87,6 +87,7 @@ static NSArray *convertJSIArrayToNSArray(jsi::Runtime &runtime, const jsi::Array
|
||||
size_t size = value.size(runtime);
|
||||
NSMutableArray *result = [NSMutableArray new];
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
// Insert kCFNull when it's `undefined` value to preserve the indices.
|
||||
[result addObject:convertJSIValueToObjCObject(runtime, value.getValueAtIndex(runtime, i), jsInvoker) ?: (id)kCFNull];
|
||||
}
|
||||
return [result copy];
|
||||
@@ -99,17 +100,22 @@ static NSDictionary *convertJSIObjectToNSDictionary(jsi::Runtime &runtime, const
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
jsi::String name = propertyNames.getValueAtIndex(runtime, i).getString(runtime);
|
||||
NSString *k = convertJSIStringToNSString(runtime, name);
|
||||
id v = convertJSIValueToObjCObject(runtime, value.getProperty(runtime, name), jsInvoker) ?: (id)kCFNull;
|
||||
result[k] = v;
|
||||
id v = convertJSIValueToObjCObject(runtime, value.getProperty(runtime, name), jsInvoker);
|
||||
if (v) {
|
||||
result[k] = v;
|
||||
}
|
||||
}
|
||||
return [result copy];
|
||||
}
|
||||
|
||||
static RCTResponseSenderBlock convertJSIFunctionToCallback(jsi::Runtime &runtime, const jsi::Function &value, std::shared_ptr<react::JSCallInvoker> jsInvoker);
|
||||
static id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, std::shared_ptr<react::JSCallInvoker> jsInvoker) {
|
||||
if (value.isUndefined() || value.isNull()) {
|
||||
if (value.isUndefined()) {
|
||||
return nil;
|
||||
}
|
||||
if (value.isNull()) {
|
||||
return (id)kCFNull;
|
||||
}
|
||||
if (value.isBool()) {
|
||||
return @(value.getBool());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user