Skip to content

Commit 32b8402

Browse files
javachefacebook-github-bot
authored andcommitted
Improve docs of onResponderGrant and expose via Pressability (facebook#38195)
Summary: Pull Request resolved: facebook#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: bc695b9f2c25b5fc9aa5b3fe30c74c129e072c98
1 parent f6c91bf commit 32b8402

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

packages/react-native/Libraries/Components/View/ViewPropTypes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ type GestureResponderEventProps = $ReadOnly<{|
164164
* `View.props.onResponderGrant: (event) => {}`, where `event` is a synthetic
165165
* touch event as described above.
166166
*
167-
* PanResponder includes a note `// TODO: t7467124 investigate if this can be removed` that
168-
* should help fixing this return type.
167+
* Return true from this callback to prevent any other native components from
168+
* becoming responder until this responder terminates (Android-only).
169169
*
170170
* See https://reactnative.dev/docs/view#onrespondergrant
171171
*/

packages/react-native/Libraries/Pressability/Pressability.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ export type PressabilityConfig = $ReadOnly<{|
134134
/**
135135
* Returns whether a long press gesture should cancel the press gesture.
136136
* Defaults to true.
137+
*
138+
* @deprecated
137139
*/
138140
onLongPressShouldCancelPress_DEPRECATED?: ?() => boolean,
139141

@@ -142,6 +144,8 @@ export type PressabilityConfig = $ReadOnly<{|
142144
*
143145
* Returns whether to yield to a lock termination request (e.g. if a native
144146
* scroll gesture attempts to steal the responder lock).
147+
*
148+
* @deprecated
145149
*/
146150
onResponderTerminationRequest_DEPRECATED?: ?() => boolean,
147151

@@ -163,7 +167,7 @@ export type EventHandlers = $ReadOnly<{|
163167
onMouseLeave?: (event: MouseEvent) => void,
164168
onPointerEnter?: (event: PointerEvent) => void,
165169
onPointerLeave?: (event: PointerEvent) => void,
166-
onResponderGrant: (event: PressEvent) => void,
170+
onResponderGrant: (event: PressEvent) => void | boolean,
167171
onResponderMove: (event: PressEvent) => void,
168172
onResponderRelease: (event: PressEvent) => void,
169173
onResponderTerminate: (event: PressEvent) => void,
@@ -464,7 +468,7 @@ export default class Pressability {
464468
return !disabled;
465469
},
466470

467-
onResponderGrant: (event: PressEvent): void => {
471+
onResponderGrant: (event: PressEvent): void | boolean => {
468472
event.persist();
469473

470474
this._cancelPressOutDelayTimeout();
@@ -490,6 +494,8 @@ export default class Pressability {
490494
this._longPressDelayTimeout = setTimeout(() => {
491495
this._handleLongPress(event);
492496
}, delayLongPress + delayPressIn);
497+
498+
return this._config.cancelable === false;
493499
},
494500

495501
onResponderMove: (event: PressEvent): void => {

0 commit comments

Comments
 (0)