Skip to content

Commit 3c3d87b

Browse files
authored
[MacOS] Fix Pressable being unresponsive (#3142)
## Description This PR fixes incorrect `Pressable` behaviour on `MacOS`, which was caused by the following sub-issues: - Pointer tracker on `MacOS` kept returning incorrect relative coordinates. This was caused by converting the `absolute` coordinates from the `local` coordinate space to the `absolute` coordinate space instead of the other way around. - There was no workflow set on the `Gesture.Native()` to allow for activation of `Pressable` ## Test plan - Open any `Pressable` example on `MacOS` - See how they all should work now.
1 parent 5730bf9 commit 3c3d87b

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

apple/RNGestureHandlerPointerTracker.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ - (int)registeredTouchesCount
7171
- (NSDictionary *)extractPointerData:(int)index forTouch:(RNGHUITouch *)touch
7272
{
7373
#if TARGET_OS_OSX
74-
CGPoint absolutePos = [touch locationInWindow];
75-
CGPoint relativePos = [touch.window.contentView convertPoint:absolutePos fromView:_gestureHandler.recognizer.view];
74+
CGFloat windowHeight = touch.window.contentView.frame.size.height;
75+
CGPoint yFlippedAbsolutePos = [touch locationInWindow];
76+
CGPoint absolutePos = CGPointMake(yFlippedAbsolutePos.x, windowHeight - yFlippedAbsolutePos.y);
77+
CGPoint relativePos = [_gestureHandler.recognizer.view convertPoint:absolutePos fromView:touch.window.contentView];
7678
#else
7779
CGPoint relativePos = [touch locationInView:_gestureHandler.recognizer.view];
7880
CGPoint absolutePos = [touch locationInView:_gestureHandler.recognizer.view.window];

src/components/Pressable/Pressable.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ export default function Pressable(props: PressableProps) {
302302
Gesture.Native()
303303
.onBegin(() => {
304304
// Android sets BEGAN state on press down
305-
if (Platform.OS === 'android') {
305+
if (Platform.OS === 'android' || Platform.OS === 'macos') {
306306
isTouchPropagationAllowed.current = true;
307307
}
308308
})
@@ -358,11 +358,7 @@ export default function Pressable(props: PressableProps) {
358358
gesture.enabled(isPressableEnabled);
359359
gesture.runOnJS(true);
360360
gesture.hitSlop(appliedHitSlop);
361-
gesture.shouldCancelWhenOutside(false);
362-
363-
if (Platform.OS !== 'web') {
364-
gesture.shouldCancelWhenOutside(true);
365-
}
361+
gesture.shouldCancelWhenOutside(Platform.OS === 'web' ? false : true);
366362
}
367363

368364
// Uses different hitSlop, to activate on hitSlop area instead of pressRetentionOffset area

0 commit comments

Comments
 (0)