Skip to content

Commit c433764

Browse files
committed
Flip coordinate space
1 parent ad0881b commit c433764

1 file changed

Lines changed: 11 additions & 25 deletions

File tree

packages/react-native-gesture-handler/apple/RNGestureHandlerButton.mm

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -100,30 +100,28 @@ - (void)setUnderlayColor:(RNGHColor *)underlayColor
100100
_underlayLayer.backgroundColor = underlayColor.CGColor;
101101
}
102102

103+
#if TARGET_OS_OSX
104+
// Flip the macOS coordinate system so y=0 is at the top, matching iOS
105+
// and React Native's layout expectations.
106+
- (BOOL)isFlipped
107+
{
108+
return YES;
109+
}
110+
#endif
111+
103112
#if !TARGET_OS_OSX
104113
- (void)layoutSubviews
105114
{
106115
[super layoutSubviews];
107-
_underlayLayer.frame = UIEdgeInsetsInsetRect(self.bounds, _underlayBorderInsets);
108-
[self.layer insertSublayer:_underlayLayer atIndex:0];
109-
[self applyUnderlayCornerRadii];
110-
}
111116
#else
112117
- (void)layout
113118
{
114119
[super layout];
115-
CGRect bounds = self.bounds;
116-
// macOS layer coordinate system has origin at bottom-left,
117-
// so the y offset uses the bottom inset, not the top.
118-
_underlayLayer.frame = CGRectMake(
119-
bounds.origin.x + _underlayBorderInsets.left,
120-
bounds.origin.y + _underlayBorderInsets.bottom,
121-
MAX(0, bounds.size.width - _underlayBorderInsets.left - _underlayBorderInsets.right),
122-
MAX(0, bounds.size.height - _underlayBorderInsets.top - _underlayBorderInsets.bottom));
120+
#endif
121+
_underlayLayer.frame = UIEdgeInsetsInsetRect(self.bounds, _underlayBorderInsets);
123122
[self.layer insertSublayer:_underlayLayer atIndex:0];
124123
[self applyUnderlayCornerRadii];
125124
}
126-
#endif
127125

128126
- (BOOL)shouldHandleTouch:(RNGHUIView *)view
129127
{
@@ -258,24 +256,12 @@ - (void)applyUnderlayCornerRadii
258256
CGFloat w = rect.size.width;
259257
CGFloat h = rect.size.height;
260258

261-
// On macOS, CALayer origin is at the bottom-left (y increases upward), so
262-
// path y=0 is the visual bottom. Swap top <-> bottom radii and border insets
263-
// so the path corners map to the correct visual corners.
264-
#if TARGET_OS_OSX
265-
const CGFloat *outerTL = &_underlayCornerRadii[4]; // path top-left = visual bottom-left
266-
const CGFloat *outerTR = &_underlayCornerRadii[6]; // path top-right = visual bottom-right
267-
const CGFloat *outerBL = &_underlayCornerRadii[0]; // path bottom-left = visual top-left
268-
const CGFloat *outerBR = &_underlayCornerRadii[2]; // path bottom-right = visual top-right
269-
CGFloat borderTop = _underlayBorderInsets.bottom;
270-
CGFloat borderBottom = _underlayBorderInsets.top;
271-
#else
272259
const CGFloat *outerTL = &_underlayCornerRadii[0];
273260
const CGFloat *outerTR = &_underlayCornerRadii[2];
274261
const CGFloat *outerBL = &_underlayCornerRadii[4];
275262
const CGFloat *outerBR = &_underlayCornerRadii[6];
276263
CGFloat borderTop = _underlayBorderInsets.top;
277264
CGFloat borderBottom = _underlayBorderInsets.bottom;
278-
#endif
279265
CGFloat borderLeft = _underlayBorderInsets.left;
280266
CGFloat borderRight = _underlayBorderInsets.right;
281267

0 commit comments

Comments
 (0)