From c004d8cad07fcb59d0d217ef31de00dfd8d34090 Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Tue, 20 Sep 2022 17:35:55 -0700 Subject: [PATCH 1/2] Update pressable hover props --- types/__typetests__/index.tsx | 16 ++++++++++++++++ types/index.d.ts | 28 ++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/types/__typetests__/index.tsx b/types/__typetests__/index.tsx index a55c2992edab69..b3982784ff8f56 100644 --- a/types/__typetests__/index.tsx +++ b/types/__typetests__/index.tsx @@ -66,6 +66,7 @@ import { LogBox, MaskedViewIOS, Modal, + MouseEvent, NativeEventEmitter, NativeModule, // Not actually exported, not sure why NativeModules, @@ -496,6 +497,12 @@ export class PressableTest extends React.Component<{}> { e.isDefaultPrevented(); }; + onHoverButton = (e: MouseEvent) => { + e.persist(); + e.isPropagationStopped(); + e.isDefaultPrevented(); + }; + render() { return ( <> @@ -550,6 +557,15 @@ export class PressableTest extends React.Component<{}> { Button + {/* onHoverIn */} + + + Button + + ); } diff --git a/types/index.d.ts b/types/index.d.ts index 96d95e1bbaec9f..4160f6ff702700 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -579,6 +579,8 @@ export type PointerEvent = NativeSyntheticEvent; export interface GestureResponderEvent extends NativeSyntheticEvent {} +export interface MouseEvent extends NativeSyntheticEvent {} + // See https://reactnative.dev/docs/scrollview#contentoffset export interface PointProp { x: number; @@ -606,6 +608,16 @@ export interface PressableAndroidRippleConfig { export interface PressableProps extends AccessibilityProps, Omit { + /** + * Called when the hover is activated to provide visual feedback. + */ + onHoverIn?: null | ((event: MouseEvent) => void) | undefined; + + /** + * Called when the hover is deactivated to undo visual feedback. + */ + onHoverOut?: null | ((event: MouseEvent) => void) | undefined; + /** * Called when a single tap gesture is detected. */ @@ -628,7 +640,7 @@ export interface PressableProps /** * Called after the element loses focus. - * @platform windows + * @platform macos windows */ onBlur?: | null @@ -637,7 +649,7 @@ export interface PressableProps /** * Called after the element is focused. - * @platform windows + * @platform macos windows */ onFocus?: | null @@ -659,6 +671,18 @@ export interface PressableProps */ cancelable?: null | boolean | undefined; + /** + * Duration to wait after hover in before calling `onHoverIn`. + * @platform macos windows + */ + delayHoverIn?: number | null | undefined; + + /** + * Duration to wait after hover out before calling `onHoverOut`. + * @platform macos windows + */ + delayHoverOut?: number | null | undefined; + /** * Duration (in milliseconds) from `onPressIn` before `onLongPress` is called. */ From f62fc176d56424128e8c79c0fae59fec396bbdaf Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Tue, 20 Sep 2022 18:24:10 -0700 Subject: [PATCH 2/2] Update index.d.ts --- types/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/index.d.ts b/types/index.d.ts index 4160f6ff702700..3d643f31aafafb 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -49,6 +49,7 @@ // Zihan Chen // Lorenzo Sciandra // Mateusz Wit +// Saad Najmi // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.0