Add cancelable prop, use mixed return type for event handlers

Summary:
Changelog:
[General][Added] Added `cancelable` prop to Pressable.
[General][Changed] Event handlers return mixed type instead of void.

Reviewed By: yungsters

Differential Revision: D26432837

fbshipit-source-id: c7bafdec085d08a06e859b45bff91a3b07d747ed
This commit is contained in:
Nadiia D 2021-02-19 17:51:43 -08:00 коммит произвёл Facebook GitHub Bot
Родитель 927573c581
Коммит 7f005e6077
1 изменённых файлов: 14 добавлений и 5 удалений

Просмотреть файл

@ -51,6 +51,12 @@ type Props = $ReadOnly<{|
importantForAccessibility?: ?('auto' | 'yes' | 'no' | 'no-hide-descendants'), importantForAccessibility?: ?('auto' | 'yes' | 'no' | 'no-hide-descendants'),
onAccessibilityAction?: ?(event: AccessibilityActionEvent) => mixed, onAccessibilityAction?: ?(event: AccessibilityActionEvent) => mixed,
/**
* Whether a press gesture can be interrupted by a parent gesture such as a
* scroll event. Defaults to true.
*/
cancelable?: ?boolean,
/** /**
* Either children or a render prop that receives a boolean reflecting whether * Either children or a render prop that receives a boolean reflecting whether
* the component is currently pressed. * the component is currently pressed.
@ -81,27 +87,27 @@ type Props = $ReadOnly<{|
/** /**
* Called when this view's layout changes. * Called when this view's layout changes.
*/ */
onLayout?: ?(event: LayoutEvent) => void, onLayout?: ?(event: LayoutEvent) => mixed,
/** /**
* Called when a long-tap gesture is detected. * Called when a long-tap gesture is detected.
*/ */
onLongPress?: ?(event: PressEvent) => void, onLongPress?: ?(event: PressEvent) => mixed,
/** /**
* Called when a single tap gesture is detected. * Called when a single tap gesture is detected.
*/ */
onPress?: ?(event: PressEvent) => void, onPress?: ?(event: PressEvent) => mixed,
/** /**
* Called when a touch is engaged before `onPress`. * Called when a touch is engaged before `onPress`.
*/ */
onPressIn?: ?(event: PressEvent) => void, onPressIn?: ?(event: PressEvent) => mixed,
/** /**
* Called when a touch is released before `onPress`. * Called when a touch is released before `onPress`.
*/ */
onPressOut?: ?(event: PressEvent) => void, onPressOut?: ?(event: PressEvent) => mixed,
/** /**
* Either view styles or a function that receives a boolean reflecting whether * Either view styles or a function that receives a boolean reflecting whether
@ -144,6 +150,7 @@ function Pressable(props: Props, forwardedRef): React.Node {
accessible, accessible,
android_disableSound, android_disableSound,
android_ripple, android_ripple,
cancelable,
children, children,
delayLongPress, delayLongPress,
disabled, disabled,
@ -184,6 +191,7 @@ function Pressable(props: Props, forwardedRef): React.Node {
const config = useMemo( const config = useMemo(
() => ({ () => ({
cancelable,
disabled, disabled,
hitSlop, hitSlop,
pressRectOffset: pressRetentionOffset, pressRectOffset: pressRetentionOffset,
@ -215,6 +223,7 @@ function Pressable(props: Props, forwardedRef): React.Node {
[ [
android_disableSound, android_disableSound,
android_rippleConfig, android_rippleConfig,
cancelable,
delayLongPress, delayLongPress,
disabled, disabled,
hitSlop, hitSlop,