Skip to content

Add example for Pressability with Native Driver in RNTester - #45413

Closed
cipolleschi wants to merge 1 commit into
react:mainfrom
cipolleschi:export-D58182480
Closed

cipolleschi wants to merge 1 commit into
react:mainfrom
cipolleschi:export-D58182480

Conversation

@cipolleschi

Copy link
Copy Markdown
Contributor

Summary:

Changes

Add an example in RNTester to test that pressability with NativeDrivers works properly.

Context

The pressability handling is a bit peculiar.
We have to handle 3 main behaviors:

  • PressIn -> PressOut => triggers the onPress
  • PressIn -> move inside the rectangle -> PressOut => triggers the onPress
  • PressIn -> move outside the rectangle -> PressOut => cancel onPress.

For the first case, we detect whether the press happens inside a component in the Native layer only. And everything works.

When a move is involved, we:

  1. Detect the initial press in the Native layer
  2. We move the coursor and we delegate the detection of whether we are inside of a rect or not to the JS layer
  3. The JS layer asks the C++ layer about the layout and decide whether we are in case 2 (move but still inside the rect) or in case 3 (move but outside the rect).

The problem is that with nativeDriver and animations, the C++ layer doesn't know about where the receiver view actually is.
This results in issues like the one shown by #36504, where the onMove is not handled correctly.

Solution

The solution is to keep detecting whether we are in the receiver view or not in the Native layer and pass the receiver view position and size back to JS so that the JS layer don't have to jump to C++ to make this decision.

We decided to pass the frame information because the JS layer is adding some padding and configurations to the final rectangle and we don't want to lose those configurations.

Changelog

[General][Added] - Add example in RNTester to show that pressability works properly with NativeDrivers

Differential Revision: D58182480

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner labels Jul 12, 2024
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D58182480

@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D58182480

Summary:
Pull Request resolved: #45413

## Changes
Add an example in RNTester to test that pressability with NativeDrivers works properly.

## Context
The pressability handling is a bit peculiar.
We have to handle 3 main behaviors:
* `PressIn` -> `PressOut` => triggers the `onPress`
* `PressIn` -> move inside the rectangle -> `PressOut` => triggers the `onPress`
* `PressIn` -> move outside the rectangle -> `PressOut` => cancel `onPress`.

For the first case, we detect whether the press happens inside a component in the Native layer only. And everything works.

When a move is involved, we:
1. Detect the initial press in the Native layer
2. We move the coursor and we delegate the detection of whether we are inside of a rect or not to the JS layer
3. The JS layer asks the C++ layer about the layout and decide whether we are in case 2 (move but still inside the rect) or in case 3 (move but outside the rect).

The problem is that with `nativeDriver` and animations, the C++ layer doesn't know about where the receiver view actually is.
This results in issues like the one shown by [#36504](#36504), where the onMove is not handled correctly.

## Solution
The solution is to keep detecting whether we are in the receiver view or not in the Native layer and pass the receiver view position and size back to JS so that the JS layer don't have to jump to C++ to make this decision.

We decided to pass the frame information because the JS layer is adding some padding and configurations to the final rectangle and we don't want to lose those configurations.

## Changelog
[General][Added] - Add example in RNTester to show that pressability works properly with NativeDrivers

Reviewed By: sammy-SC

Differential Revision: D58182480
@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D58182480

@facebook-github-bot

Copy link
Copy Markdown
Contributor

This pull request has been merged in 050006a.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jul 16, 2024
@github-actions

Copy link
Copy Markdown

This pull request was successfully merged by @cipolleschi in 050006a

When will my fix make it into a release? | How to file a pick request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants