Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve docs of onResponderGrant and expose via Pressability #38195

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 callback to prevent any other native components from
* becoming responder until this responder terminates (Android-only).
*
* See https://reactnative.dev/docs/view#onrespondergrant
*/
Expand Down
10 changes: 8 additions & 2 deletions packages/react-native/Libraries/Pressability/Pressability.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ export type PressabilityConfig = $ReadOnly<{|
/**
* Returns whether a long press gesture should cancel the press gesture.
* Defaults to true.
*
* @deprecated
*/
onLongPressShouldCancelPress_DEPRECATED?: ?() => boolean,

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

Expand All @@ -163,7 +167,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 +468,7 @@ export default class Pressability {
return !disabled;
},

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

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

return this._config.cancelable === false;
},

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