Skip to content

Commit

Permalink
[macOS] Switch hasPointerInside to containsPointInView (#3012)
Browse files Browse the repository at this point in the history
## Description

While working on `LongPress` I've noticed that currently check if pointer is inside view is implemented inside `NativeViewGestureHandler`. I've decided to move it to `GestureHandler` to be able to use it in other places.

### `HitSlop`

Current implementation of `containsPointInView` also takes into consideration `HitSlop` property. The only problem is that on `macOS` we cannot detect clicks outside of view using `mouseDown`.  This means that `HitSlop` will work only if click was started inside view - clicking on `HitSlop` area won't activate handlers.

## Test plan

Tested on example app. You can simply see that `RectButtons` navigate to examples - it doesn't work if `pointerInside` is `false`.

<details>
<summary>Also tested on the following code:</summary>

```tsx
export default function App() {
  return (
    <GestureHandlerRootView style={styles.container}>
      <RectButton style={styles.button} hitSlop={10} onPress={console.log} />
    </GestureHandlerRootView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'space-around',
    alignItems: 'center',
  },
  button: {
    width: 100,
    height: 30,
    borderRadius: 15,
    backgroundColor: 'crimson',
  },
});
```

</details>
  • Loading branch information
m-bert authored Jul 29, 2024
1 parent 7050c1b commit 0e4db18
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions apple/Handlers/RNNativeViewHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ - (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)ev
}

#else
- (BOOL)hasPointerInside
{
return NSPointInRect([self locationInView:self.view], self.view.bounds);
}

- (void)mouseDown:(NSEvent *)event
{
[_gestureHandler setCurrentPointerTypeToMouse];
Expand Down Expand Up @@ -231,7 +226,7 @@ - (void)handleTouchCancel:(UIView *)sender forEvent:(UIEvent *)event

- (RNGestureHandlerEventExtraData *)eventExtraData:(RNDummyGestureRecognizer *)recognizer
{
return [RNGestureHandlerEventExtraData forPointerInside:[recognizer hasPointerInside]
return [RNGestureHandlerEventExtraData forPointerInside:[self containsPointInView]
withPointerType:RNGestureHandlerMouse];
}

Expand Down

0 comments on commit 0e4db18

Please sign in to comment.