mirror of
https://github.com/status-im/react-native.git
synced 2025-02-09 16:14:47 +00:00
Fix crash when converting NSNull values
Reviewed By: fkgozali Differential Revision: D5583401 fbshipit-source-id: 7adbdaf91c3f7d9a87f44c53ff342c54a04a1e50
This commit is contained in:
parent
0241cb76d1
commit
b06bfdd280
@ -398,8 +398,7 @@ RCT_ENUM_CONVERTER(UIBarStyle, (@{
|
|||||||
}), UIBarStyleDefault, integerValue)
|
}), UIBarStyleDefault, integerValue)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO: normalise the use of w/width so we can do away with the alias values (#6566645)
|
static void convertCGStruct(const char *type, NSArray *fields, CGFloat *result, id json)
|
||||||
static void RCTConvertCGStructValue(const char *type, NSArray *fields, NSDictionary *aliases, CGFloat *result, id json)
|
|
||||||
{
|
{
|
||||||
NSUInteger count = fields.count;
|
NSUInteger count = fields.count;
|
||||||
if ([json isKindOfClass:[NSArray class]]) {
|
if ([json isKindOfClass:[NSArray class]]) {
|
||||||
@ -407,23 +406,12 @@ static void RCTConvertCGStructValue(const char *type, NSArray *fields, NSDiction
|
|||||||
RCTLogError(@"Expected array with count %zd, but count is %zd: %@", count, [json count], json);
|
RCTLogError(@"Expected array with count %zd, but count is %zd: %@", count, [json count], json);
|
||||||
} else {
|
} else {
|
||||||
for (NSUInteger i = 0; i < count; i++) {
|
for (NSUInteger i = 0; i < count; i++) {
|
||||||
result[i] = [RCTConvert CGFloat:json[i]];
|
result[i] = [RCTConvert CGFloat:RCTNilIfNull(json[i])];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ([json isKindOfClass:[NSDictionary class]]) {
|
} else if ([json isKindOfClass:[NSDictionary class]]) {
|
||||||
if (aliases.count) {
|
|
||||||
json = [json mutableCopy];
|
|
||||||
for (NSString *alias in aliases) {
|
|
||||||
NSString *key = aliases[alias];
|
|
||||||
NSNumber *number = json[alias];
|
|
||||||
if (number != nil) {
|
|
||||||
RCTLogWarn(@"Using deprecated '%@' property for '%s'. Use '%@' instead.", alias, type, key);
|
|
||||||
((NSMutableDictionary *)json)[key] = number;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (NSUInteger i = 0; i < count; i++) {
|
for (NSUInteger i = 0; i < count; i++) {
|
||||||
result[i] = [RCTConvert CGFloat:json[fields[i]]];
|
result[i] = [RCTConvert CGFloat:RCTNilIfNull(json[fields[i]])];
|
||||||
}
|
}
|
||||||
} else if (json) {
|
} else if (json) {
|
||||||
RCTLogConvertError(json, @(type));
|
RCTLogConvertError(json, @(type));
|
||||||
@ -434,7 +422,7 @@ static void RCTConvertCGStructValue(const char *type, NSArray *fields, NSDiction
|
|||||||
* This macro is used for creating converter functions for structs that consist
|
* This macro is used for creating converter functions for structs that consist
|
||||||
* of a number of CGFloat properties, such as CGPoint, CGRect, etc.
|
* of a number of CGFloat properties, such as CGPoint, CGRect, etc.
|
||||||
*/
|
*/
|
||||||
#define RCT_CGSTRUCT_CONVERTER(type, values, aliases) \
|
#define RCT_CGSTRUCT_CONVERTER(type, values) \
|
||||||
+ (type)type:(id)json \
|
+ (type)type:(id)json \
|
||||||
{ \
|
{ \
|
||||||
static NSArray *fields; \
|
static NSArray *fields; \
|
||||||
@ -443,15 +431,16 @@ static void RCTConvertCGStructValue(const char *type, NSArray *fields, NSDiction
|
|||||||
fields = values; \
|
fields = values; \
|
||||||
}); \
|
}); \
|
||||||
type result; \
|
type result; \
|
||||||
RCTConvertCGStructValue(#type, fields, aliases, (CGFloat *)&result, json); \
|
convertCGStruct(#type, fields, (CGFloat *)&result, json); \
|
||||||
return result; \
|
return result; \
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_CUSTOM_CONVERTER(CGFloat, CGFloat, [self double:json])
|
RCT_CUSTOM_CONVERTER(CGFloat, CGFloat, [self double:json])
|
||||||
RCT_CGSTRUCT_CONVERTER(CGPoint, (@[@"x", @"y"]), (@{@"l": @"x", @"t": @"y"}))
|
|
||||||
RCT_CGSTRUCT_CONVERTER(CGSize, (@[@"width", @"height"]), (@{@"w": @"width", @"h": @"height"}))
|
RCT_CGSTRUCT_CONVERTER(CGPoint, (@[@"x", @"y"]))
|
||||||
RCT_CGSTRUCT_CONVERTER(CGRect, (@[@"x", @"y", @"width", @"height"]), (@{@"l": @"x", @"t": @"y", @"w": @"width", @"h": @"height"}))
|
RCT_CGSTRUCT_CONVERTER(CGSize, (@[@"width", @"height"]))
|
||||||
RCT_CGSTRUCT_CONVERTER(UIEdgeInsets, (@[@"top", @"left", @"bottom", @"right"]), nil)
|
RCT_CGSTRUCT_CONVERTER(CGRect, (@[@"x", @"y", @"width", @"height"]))
|
||||||
|
RCT_CGSTRUCT_CONVERTER(UIEdgeInsets, (@[@"top", @"left", @"bottom", @"right"]))
|
||||||
|
|
||||||
RCT_ENUM_CONVERTER(CGLineJoin, (@{
|
RCT_ENUM_CONVERTER(CGLineJoin, (@{
|
||||||
@"miter": @(kCGLineJoinMiter),
|
@"miter": @(kCGLineJoinMiter),
|
||||||
@ -467,7 +456,7 @@ RCT_ENUM_CONVERTER(CGLineCap, (@{
|
|||||||
|
|
||||||
RCT_CGSTRUCT_CONVERTER(CGAffineTransform, (@[
|
RCT_CGSTRUCT_CONVERTER(CGAffineTransform, (@[
|
||||||
@"a", @"b", @"c", @"d", @"tx", @"ty"
|
@"a", @"b", @"c", @"d", @"tx", @"ty"
|
||||||
]), nil)
|
]))
|
||||||
|
|
||||||
+ (UIColor *)UIColor:(id)json
|
+ (UIColor *)UIColor:(id)json
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user