Skip to content

Commit

Permalink
[MacOS] Fix Pressable being unresponsive (#3142)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
latekvo authored Oct 9, 2024
1 parent 5730bf9 commit 3c3d87b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 4 additions & 2 deletions apple/RNGestureHandlerPointerTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ - (int)registeredTouchesCount
- (NSDictionary *)extractPointerData:(int)index forTouch:(RNGHUITouch *)touch
{
#if TARGET_OS_OSX
CGPoint absolutePos = [touch locationInWindow];
CGPoint relativePos = [touch.window.contentView convertPoint:absolutePos fromView:_gestureHandler.recognizer.view];
CGFloat windowHeight = touch.window.contentView.frame.size.height;
CGPoint yFlippedAbsolutePos = [touch locationInWindow];
CGPoint absolutePos = CGPointMake(yFlippedAbsolutePos.x, windowHeight - yFlippedAbsolutePos.y);
CGPoint relativePos = [_gestureHandler.recognizer.view convertPoint:absolutePos fromView:touch.window.contentView];
#else
CGPoint relativePos = [touch locationInView:_gestureHandler.recognizer.view];
CGPoint absolutePos = [touch locationInView:_gestureHandler.recognizer.view.window];
Expand Down
8 changes: 2 additions & 6 deletions src/components/Pressable/Pressable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ export default function Pressable(props: PressableProps) {
Gesture.Native()
.onBegin(() => {
// Android sets BEGAN state on press down
if (Platform.OS === 'android') {
if (Platform.OS === 'android' || Platform.OS === 'macos') {
isTouchPropagationAllowed.current = true;
}
})
Expand Down Expand Up @@ -358,11 +358,7 @@ export default function Pressable(props: PressableProps) {
gesture.enabled(isPressableEnabled);
gesture.runOnJS(true);
gesture.hitSlop(appliedHitSlop);
gesture.shouldCancelWhenOutside(false);

if (Platform.OS !== 'web') {
gesture.shouldCancelWhenOutside(true);
}
gesture.shouldCancelWhenOutside(Platform.OS === 'web' ? false : true);
}

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

0 comments on commit 3c3d87b

Please sign in to comment.