Skip to content

Commit

Permalink
Improve docs of onResponderGrant and expose via Pressability (#38195)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #38195

`onResponderGrant`'s return value drives the `blockNativeResponder` value for the `setIsJSResponder` native callback. On Android this is used to call `requestDisallowInterceptTouchEvent`, which can be used to prevent a scrollview from activating while another responder is active.

Changelog: [Improved] Exposed ability to block native responder in Pressability.

Differential Revision: D47225928

fbshipit-source-id: 52a88936a1243c63ef93a6aa43fbcb587e6aa873
  • Loading branch information
javache authored and facebook-github-bot committed Jul 5, 2023
1 parent 5846be0 commit 3386956
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ type GestureResponderEventProps = $ReadOnly<{|
* `View.props.onResponderGrant: (event) => {}`, where `event` is a synthetic
* touch event as described above.
*
* PanResponder includes a note `// TODO: t7467124 investigate if this can be removed` that
* should help fixing this return type.
* Return true from this grant to prevent any other native components from
* becoming responder until this responder is finished (Android-only).
*
* See https://reactnative.dev/docs/view#onrespondergrant
*/
Expand Down
12 changes: 10 additions & 2 deletions packages/react-native/Libraries/Pressability/Pressability.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ export type PressabilityConfig = $ReadOnly<{|
*/
onPressOut?: ?(event: PressEvent) => mixed,

/**
* Whether to prevent any other native components from becoming responder
* while this pressable is responder.
*/
blockNativeResponder?: void | boolean,

/**
* Returns whether a long press gesture should cancel the press gesture.
* Defaults to true.
Expand Down Expand Up @@ -163,7 +169,7 @@ export type EventHandlers = $ReadOnly<{|
onMouseLeave?: (event: MouseEvent) => void,
onPointerEnter?: (event: PointerEvent) => void,
onPointerLeave?: (event: PointerEvent) => void,
onResponderGrant: (event: PressEvent) => void,
onResponderGrant: (event: PressEvent) => void | boolean,
onResponderMove: (event: PressEvent) => void,
onResponderRelease: (event: PressEvent) => void,
onResponderTerminate: (event: PressEvent) => void,
Expand Down Expand Up @@ -464,7 +470,7 @@ export default class Pressability {
return !disabled;
},

onResponderGrant: (event: PressEvent): void => {
onResponderGrant: (event: PressEvent): void | boolean => {
event.persist();

this._cancelPressOutDelayTimeout();
Expand All @@ -490,6 +496,8 @@ export default class Pressability {
this._longPressDelayTimeout = setTimeout(() => {
this._handleLongPress(event);
}, delayLongPress + delayPressIn);

return this._config.blockNativeResponder;
},

onResponderMove: (event: PressEvent): void => {
Expand Down

0 comments on commit 3386956

Please sign in to comment.