Skip to content

Commit

Permalink
Support constructing UIEdgeInsets with single value
Browse files Browse the repository at this point in the history
Summary:
This is only required in the old renderer, as in Fabric the parsing behaviour is shared across platforms (https://github.com/facebook/react-native/blob/main/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm#L264). JS changes are following in D33453327.

Changelog: [iOS][Fixed] Enable hitSlop to be set using a single number.

Reviewed By: philIip

Differential Revision: D33453326

fbshipit-source-id: f15a4fd1d26dcac6f40b064be1a8266051b6aedf
  • Loading branch information
javache authored and facebook-github-bot committed Jan 19, 2022
1 parent a46a99e commit 3addafa
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion React/Base/RCTConvert.m
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,24 @@ +(type)type : (id)json \
RCT_CGSTRUCT_CONVERTER(CGPoint, (@[ @"x", @"y" ]))
RCT_CGSTRUCT_CONVERTER(CGSize, (@[ @"width", @"height" ]))
RCT_CGSTRUCT_CONVERTER(CGRect, (@[ @"x", @"y", @"width", @"height" ]))
RCT_CGSTRUCT_CONVERTER(UIEdgeInsets, (@[ @"top", @"left", @"bottom", @"right" ]))

+ (UIEdgeInsets)UIEdgeInsets:(id)json
{
static NSArray *fields;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
fields = @[ @"top", @"left", @"bottom", @"right" ];
});

if ([json isKindOfClass:[NSNumber class]]) {
CGFloat value = [json doubleValue];
return UIEdgeInsetsMake(value, value, value, value);
} else {
UIEdgeInsets result;
convertCGStruct("UIEdgeInsets", fields, (CGFloat *)&result, json);
return result;
}
}

RCT_ENUM_CONVERTER(
CGLineJoin,
Expand Down

0 comments on commit 3addafa

Please sign in to comment.