Skip to content

Commit 29de1d0

Browse files
authored
[0.63] Pull in upstream fixes to expose hover props on Pressable #884 (#887)
* Expose Pressability Hover config props in Pressable (facebook#32405) Summary: Several desktop forks (`react-native-macos`, `react-native-windows`, `react-native-web`) support mouse events, and while the stock Pressable component has the ability to support mouse events, it seems we aren't forwarding some props properly from Pressable -> Pressability. Pressability will calculate onMouseEnter / onMouseLeave event handlers based on the `onHoverIn/onHoverOut` callbacks passed into PressabilityConfig. https://github.com/facebook/react-native/blob/ad0d4534a751ed05f84ff971714c8f7a4d1deb3a/Libraries/Pressability/Pressability.js#L552 However, Pressable does not pass take in onHoverIn/onHoverOut props to pass to PressabilityConfig, so we can't take advantage of this functionality. This change should simply address that by passing the props through. <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [General] [Fixed] - Pressabel not passing hover props and event handlers to PressabilityConfig Pull Request resolved: facebook#32405 Test Plan: I fixed a similar issue in `react-native-macos` that I am now trying to contribute back upstream. #855 Reviewed By: yungsters Differential Revision: D31667737 Pulled By: sota000 fbshipit-source-id: f0bbe48302703bb2c45280d2afeec8d7a4586b6a * Additional changes * undo extra unnecessary changes * remove another line * update podfile lock
1 parent 3aa7acb commit 29de1d0

File tree

3 files changed

+271
-247
lines changed

3 files changed

+271
-247
lines changed

Libraries/Components/Pressable/Pressable.js

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {normalizeRect, type RectOrSize} from '../../StyleSheet/Rect';
2828
import type {ColorValue} from '../../StyleSheet/StyleSheetTypes';
2929
import type {
3030
LayoutEvent,
31-
MouseEvent, // TODO(macOS ISS#2323203)
31+
MouseEvent,
3232
PressEvent,
3333
} from '../../Types/CoreEventTypes';
3434
import type {DraggedTypesType} from '../View/DraggedType'; // TODO(macOS ISS#2323203)
@@ -65,6 +65,16 @@ type Props = $ReadOnly<{|
6565
*/
6666
children: React.Node | ((state: StateCallbackType) => React.Node),
6767

68+
/**
69+
* Duration to wait after hover in before calling `onHoverIn`.
70+
*/
71+
delayHoverIn?: ?number,
72+
73+
/**
74+
* Duration to wait after hover out before calling `onHoverOut`.
75+
*/
76+
delayHoverOut?: ?number,
77+
6878
/**
6979
* Duration (in milliseconds) from `onPressIn` before `onLongPress` is called.
7080
*/
@@ -91,6 +101,16 @@ type Props = $ReadOnly<{|
91101
*/
92102
onLayout?: ?(event: LayoutEvent) => void,
93103

104+
/**
105+
* Called when the hover is activated to provide visual feedback.
106+
*/
107+
onHoverIn?: ?(event: MouseEvent) => mixed,
108+
109+
/**
110+
* Called when the hover is deactivated to undo visual feedback.
111+
*/
112+
onHoverOut?: ?(event: MouseEvent) => mixed,
113+
94114
/**
95115
* Called when a long-tap gesture is detected.
96116
*/
@@ -141,8 +161,6 @@ type Props = $ReadOnly<{|
141161
acceptsFirstMouse?: ?boolean,
142162
enableFocusRing?: ?boolean,
143163
tooltip?: ?string,
144-
onMouseEnter?: (event: MouseEvent) => void,
145-
onMouseLeave?: (event: MouseEvent) => void,
146164
onDragEnter?: (event: MouseEvent) => void,
147165
onDragLeave?: (event: MouseEvent) => void,
148166
onDrop?: (event: MouseEvent) => void,
@@ -162,11 +180,13 @@ function Pressable(props: Props, forwardedRef): React.Node {
162180
android_disableSound,
163181
android_ripple,
164182
children,
183+
delayHoverIn,
184+
delayHoverOut,
165185
delayLongPress,
166186
disabled,
167187
focusable,
168-
onMouseEnter, // [TODO(macOS GH#774)
169-
onMouseLeave, // ]TODO(macOS GH#774)
188+
onHoverIn,
189+
onHoverOut,
170190
onLongPress,
171191
onPress,
172192
onPressIn,
@@ -192,9 +212,11 @@ function Pressable(props: Props, forwardedRef): React.Node {
192212
hitSlop,
193213
pressRectOffset: pressRetentionOffset,
194214
android_disableSound,
215+
delayHoverIn,
216+
delayHoverOut,
195217
delayLongPress,
196-
onHoverIn: onMouseEnter, // [TODO(macOS GH#774)
197-
onHoverOut: onMouseLeave, // ]TODO(macOS GH#774)
218+
onHoverIn,
219+
onHoverOut,
198220
onLongPress,
199221
onPress,
200222
onPressIn(event: PressEvent): void {
@@ -220,11 +242,13 @@ function Pressable(props: Props, forwardedRef): React.Node {
220242
[
221243
android_disableSound,
222244
android_rippleConfig,
245+
delayHoverIn,
246+
delayHoverOut,
223247
delayLongPress,
224248
disabled,
225249
hitSlop,
226-
onMouseEnter, // [TODO(macOS GH#774)
227-
onMouseLeave, // ]TODO(macOS GH#774)
250+
onHoverIn,
251+
onHoverOut,
228252
onLongPress,
229253
onPress,
230254
onPressIn,

0 commit comments

Comments
 (0)