Skip to content

Commit

Permalink
Update pressable hover props (#34740)
Browse files Browse the repository at this point in the history
Summary:
This is a mirror of DefinitelyTyped/DefinitelyTyped#62344 . I am updating some typescript types for props that were added with #32405

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[General] [Fixed] - Fixed missing Pressable hover props in typescript definition

Pull Request resolved: #34740

Test Plan: Added a test case.

Reviewed By: lunaleaps

Differential Revision: D39688606

Pulled By: cortinico

fbshipit-source-id: 98ea5f64e6ac264772466455e6d5ab99a8427d3a
  • Loading branch information
Saadnajmi authored and facebook-github-bot committed Sep 21, 2022
1 parent eddff32 commit 6ba5fa9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
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

0 comments on commit 6ba5fa9

Please sign in to comment.