Skip to content
Merged
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
29 changes: 27 additions & 2 deletions types/react-native/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
// Lorenzo Sciandra <https://github.com/kelset>
// Mateusz Wit <https://github.com/MateWW>
// Luna Wei <https://github.com/lunaleaps>
// Saad Najmi <https://github.com/saadnajmi>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0

Expand Down Expand Up @@ -546,6 +547,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 All @@ -571,6 +574,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 @@ -593,13 +606,13 @@ export interface PressableProps extends AccessibilityProps, Omit<ViewProps, 'chi

/**
* Called after the element loses focus.
* @platform windows
* @platform macos windows
*/
onBlur?: null | ((event: NativeSyntheticEvent<TargetedEvent>) => void) | undefined;

/**
* Called after the element is focused.
* @platform windows
* @platform macos windows
*/
onFocus?: null | ((event: NativeSyntheticEvent<TargetedEvent>) => void) | undefined;

Expand All @@ -615,6 +628,18 @@ export interface PressableProps extends AccessibilityProps, Omit<ViewProps, 'chi
*/
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
13 changes: 13 additions & 0 deletions types/react-native/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import {
LogBox,
MaskedViewIOS,
Modal,
MouseEvent,
NativeEventEmitter,
NativeModule, // Not actually exported, not sure why
NativeModules,
Expand Down Expand Up @@ -438,6 +439,12 @@ export class PressableTest extends React.Component<{}> {
e.isDefaultPrevented();
};

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

render() {
return (
<>
Expand Down Expand Up @@ -491,6 +498,12 @@ 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
35 changes: 33 additions & 2 deletions types/react-native/v0.68/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
// Pedro Hernández <https://github.com/phvillegas>
// Sebastian Silbermann <https://github.com/eps1lon>
// Zihan Chen <https://github.com/ZihanChen-MSFT>
// Saad Najmi <https://github.com/saadnajmi>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0

Expand Down Expand Up @@ -424,8 +425,18 @@ export interface NativeTouchEvent {
force?: number | undefined;
}

export interface NativeMouseEvent {
clientX: number,
clientY: number,
pageX: number,
pageY: number,
timestamp: number,
}

export interface GestureResponderEvent extends NativeSyntheticEvent<NativeTouchEvent> {}

export interface MouseEvent extends NativeSyntheticEvent<NativeMouseEvent> {}

// See https://reactnative.dev/docs/scrollview#contentoffset
export interface PointPropType {
x: number;
Expand All @@ -451,6 +462,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 @@ -473,13 +494,13 @@ export interface PressableProps extends AccessibilityProps, Omit<ViewProps, 'chi

/**
* Called after the element loses focus.
* @platform windows
* @platform macos windows
*/
onBlur?: null | ((event: NativeSyntheticEvent<TargetedEvent>) => void) | undefined;

/**
* Called after the element is focused.
* @platform windows
* @platform macos windows
*/
onFocus?: null | ((event: NativeSyntheticEvent<TargetedEvent>) => void) | undefined;

Expand All @@ -495,6 +516,16 @@ export interface PressableProps extends AccessibilityProps, Omit<ViewProps, 'chi
*/
cancelable?: null | boolean | undefined;

/**
* Duration to wait after hover in before calling `onHoverIn`.
*/
delayHoverIn?: number | null | undefined;

/**
* Duration to wait after hover out before calling `onHoverOut`.
*/
delayHoverOut?: number | null | undefined;

/**
* Duration (in milliseconds) from `onPressIn` before `onLongPress` is called.
*/
Expand Down
35 changes: 33 additions & 2 deletions types/react-native/v0.69/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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 @@ -427,8 +428,18 @@ export interface NativeTouchEvent {
force?: number | undefined;
}

export interface NativeMouseEvent {
clientX: number,
clientY: number,
pageX: number,
pageY: number,
timestamp: number,
}

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 All @@ -454,6 +465,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 @@ -476,13 +497,13 @@ export interface PressableProps extends AccessibilityProps, Omit<ViewProps, 'chi

/**
* Called after the element loses focus.
* @platform windows
* @platform macos windows
*/
onBlur?: null | ((event: NativeSyntheticEvent<TargetedEvent>) => void) | undefined;

/**
* Called after the element is focused.
* @platform windows
* @platform macos windows
*/
onFocus?: null | ((event: NativeSyntheticEvent<TargetedEvent>) => void) | undefined;

Expand All @@ -498,6 +519,16 @@ export interface PressableProps extends AccessibilityProps, Omit<ViewProps, 'chi
*/
cancelable?: null | boolean | undefined;

/**
* Duration to wait after hover in before calling `onHoverIn`.
*/
delayHoverIn?: number | null | undefined;

/**
* Duration to wait after hover out before calling `onHoverOut`.
*/
delayHoverOut?: number | null | undefined;

/**
* Duration (in milliseconds) from `onPressIn` before `onLongPress` is called.
*/
Expand Down