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

Update pressable hover props #34740

Closed
wants to merge 2 commits 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
16 changes: 16 additions & 0 deletions types/__typetests__/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import {
LogBox,
MaskedViewIOS,
Modal,
MouseEvent,
NativeEventEmitter,
NativeModule, // Not actually exported, not sure why
NativeModules,
Expand Down Expand Up @@ -496,6 +497,12 @@ export class PressableTest extends React.Component<{}> {
e.isDefaultPrevented();
};

onHoverButton = (e: MouseEvent) => {
e.persist();
e.isPropagationStopped();
e.isDefaultPrevented();
};

render() {
return (
<>
Expand Down Expand Up @@ -550,6 +557,15 @@ export class PressableTest extends React.Component<{}> {
<Text style={{margin: 30}}>Button</Text>
</View>
</Pressable>
{/* onHoverIn */}
<Pressable
ref={this.myRef}
onHoverIn={this.onHoverButton}
style={{backgroundColor: 'blue'}}>
<View style={{width: 150, height: 100, backgroundColor: 'red'}}>
<Text style={{margin: 30}}>Button</Text>
</View>
</Pressable>
</>
);
}
Expand Down
29 changes: 27 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
// Zihan Chen <https://github.com/ZihanChen-MSFT>
// Lorenzo Sciandra <https://github.com/kelset>
// Mateusz Wit <https://github.com/MateWW>
// Saad Najmi <https://github.com/saadnajmi>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0

Expand Down Expand Up @@ -579,6 +580,8 @@ export type PointerEvent = NativeSyntheticEvent<NativePointerEvent>;
export interface GestureResponderEvent
extends NativeSyntheticEvent<NativeTouchEvent> {}

export interface MouseEvent extends NativeSyntheticEvent<NativeMouseEvent> {}

// See https://reactnative.dev/docs/scrollview#contentoffset
export interface PointProp {
x: number;
Expand Down Expand Up @@ -606,6 +609,16 @@ export interface PressableAndroidRippleConfig {
export interface PressableProps
extends AccessibilityProps,
Omit<ViewProps, 'children' | 'style' | 'hitSlop'> {
/**
* 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.
*/
Expand All @@ -628,7 +641,7 @@ export interface PressableProps

/**
* Called after the element loses focus.
* @platform windows
* @platform macos windows
*/
onBlur?:
| null
Expand All @@ -637,7 +650,7 @@ export interface PressableProps

/**
* Called after the element is focused.
* @platform windows
* @platform macos windows
*/
onFocus?:
| null
Expand All @@ -659,6 +672,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.
*/
Expand Down