Skip to content

Commit

Permalink
Border Radius percentage should be disabled on Paper (facebook#46179)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#46179

Changelog: [Internal]

**Context**

- When debugging E2E tests, we found RNTester Legacy Arch builds were rendering border radius w/ percentages in a strange way
- The issues was only noticeable on production e2e builds
- Support for percentage on borderRadius ViewStyle props was added in D56198302
- This should be fabric only, but the same props are parsed on Paper

**Change**

- Add Custom Conversion for BorderRadius on Paper
- Only Parse integer border radius values

Reviewed By: philIip

Differential Revision: D61686841

fbshipit-source-id: cc24d3dbdb82b1dcb90f18fc44d5d13d3e6465b4
  • Loading branch information
shwanton authored and facebook-github-bot committed Aug 24, 2024
1 parent 09e8844 commit 6cfe51d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
3 changes: 3 additions & 0 deletions packages/react-native/React/Views/RCTViewManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,7 @@ typedef void (^RCTViewManagerUIBlock)(RCTUIManager *uiManager, NSDictionary<NSNu
RCT_REMAP_SHADOW_PROPERTY(name, __custom__, type) \
-(void)set_##name : (id)json forShadowView : (viewClass *)view RCT_DYNAMIC

// Parse a JSON object and only return the number value, eveything else returns a 0
CGFloat RCTJSONParseOnlyNumber(id json);

@end
24 changes: 16 additions & 8 deletions packages/react-native/React/Views/RCTViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,9 @@ - (void)updateAccessibilityTraitsForRole:(RCTView *)view withDefaultView:(RCTVie
RCT_CUSTOM_VIEW_PROPERTY(borderRadius, CGFloat, RCTView)
{
if ([view respondsToSelector:@selector(setBorderRadius:)]) {
view.borderRadius = json ? [RCTConvert CGFloat:json] : defaultView.borderRadius;
view.borderRadius = json ? RCTJSONParseOnlyNumber(json) : defaultView.borderRadius;
} else {
view.layer.cornerRadius = json ? [RCTConvert CGFloat:json] : defaultView.layer.cornerRadius;
view.layer.cornerRadius = json ? RCTJSONParseOnlyNumber(json) : defaultView.layer.cornerRadius;
}
}
RCT_CUSTOM_VIEW_PROPERTY(borderColor, UIColor, RCTView)
Expand Down Expand Up @@ -476,12 +476,12 @@ - (void)updateAccessibilityTraitsForRole:(RCTView *)view withDefaultView:(RCTVie
RCT_VIEW_BORDER_PROPERTY(BlockEnd)
RCT_VIEW_BORDER_PROPERTY(BlockStart)

#define RCT_VIEW_BORDER_RADIUS_PROPERTY(SIDE) \
RCT_CUSTOM_VIEW_PROPERTY(border##SIDE##Radius, CGFloat, RCTView) \
{ \
if ([view respondsToSelector:@selector(setBorder##SIDE##Radius:)]) { \
view.border##SIDE##Radius = json ? [RCTConvert CGFloat:json] : defaultView.border##SIDE##Radius; \
} \
#define RCT_VIEW_BORDER_RADIUS_PROPERTY(SIDE) \
RCT_CUSTOM_VIEW_PROPERTY(border##SIDE##Radius, CGFloat, RCTView) \
{ \
if ([view respondsToSelector:@selector(setBorder##SIDE##Radius:)]) { \
view.border##SIDE##Radius = json ? RCTJSONParseOnlyNumber(json) : defaultView.border##SIDE##Radius; \
} \
}

RCT_VIEW_BORDER_RADIUS_PROPERTY(TopLeft)
Expand Down Expand Up @@ -739,4 +739,12 @@ - (void)updateAccessibilityTraitsForRole:(RCTView *)view withDefaultView:(RCTVie
RCT_EXPORT_VIEW_PROPERTY(onGotPointerCapture, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onLostPointerCapture, RCTBubblingEventBlock)

CGFloat RCTJSONParseOnlyNumber(id json)
{
if ([json isKindOfClass:[NSNumber class]]) {
return [RCTConvert CGFloat:json];
}
return 0.0f;
}

@end

0 comments on commit 6cfe51d

Please sign in to comment.