Skip to content

Commit b0c134a

Browse files
authored
[0.64] Pull in upstream fixes to expose hover props on Pressable #884 (#923)
* 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 * Add back macOS test * update podfile * remove unnecessary line * update podfile
1 parent 9d0fa3e commit b0c134a

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

Libraries/Components/Pressable/Pressable.js

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ import type {
2525
import {PressabilityDebugView} from '../../Pressability/PressabilityDebug';
2626
import usePressability from '../../Pressability/usePressability';
2727
import {normalizeRect, type RectOrSize} from '../../StyleSheet/Rect';
28-
import type {ColorValue} from '../../StyleSheet/StyleSheet';
2928
import type {
3029
LayoutEvent,
31-
MouseEvent, // TODO(macOS GH#774)
30+
MouseEvent,
3231
PressEvent,
3332
} from '../../Types/CoreEventTypes';
3433
import type {DraggedTypesType} from '../View/DraggedType'; // TODO(macOS GH#774)
@@ -65,6 +64,16 @@ type Props = $ReadOnly<{|
6564
*/
6665
children: React.Node | ((state: StateCallbackType) => React.Node),
6766

67+
/**
68+
* Duration to wait after hover in before calling `onHoverIn`.
69+
*/
70+
delayHoverIn?: ?number,
71+
72+
/**
73+
* Duration to wait after hover out before calling `onHoverOut`.
74+
*/
75+
delayHoverOut?: ?number,
76+
6877
/**
6978
* Duration (in milliseconds) from `onPressIn` before `onLongPress` is called.
7079
*/
@@ -91,6 +100,16 @@ type Props = $ReadOnly<{|
91100
*/
92101
onLayout?: ?(event: LayoutEvent) => void,
93102

103+
/**
104+
* Called when the hover is activated to provide visual feedback.
105+
*/
106+
onHoverIn?: ?(event: MouseEvent) => mixed,
107+
108+
/**
109+
* Called when the hover is deactivated to undo visual feedback.
110+
*/
111+
onHoverOut?: ?(event: MouseEvent) => mixed,
112+
94113
/**
95114
* Called when a long-tap gesture is detected.
96115
*/
@@ -167,11 +186,13 @@ function Pressable(props: Props, forwardedRef): React.Node {
167186
android_disableSound,
168187
android_ripple,
169188
children,
189+
delayHoverIn,
190+
delayHoverOut,
170191
delayLongPress,
171192
disabled,
172193
focusable,
173-
onMouseEnter, // [TODO(macOS GH#774)
174-
onMouseLeave, // ]TODO(macOS GH#774)
194+
onHoverIn,
195+
onHoverOut,
175196
onLongPress,
176197
onPress,
177198
onPressIn,
@@ -208,10 +229,12 @@ function Pressable(props: Props, forwardedRef): React.Node {
208229
hitSlop,
209230
pressRectOffset: pressRetentionOffset,
210231
android_disableSound,
232+
delayHoverIn,
233+
delayHoverOut,
211234
delayLongPress,
212235
delayPressIn: unstable_pressDelay,
213-
onHoverIn: onMouseEnter, // [TODO(macOS GH#774)
214-
onHoverOut: onMouseLeave, // ]TODO(macOS GH#774)
236+
onHoverIn,
237+
onHoverOut,
215238
onLongPress,
216239
onPress,
217240
onPressIn(event: PressEvent): void {
@@ -237,11 +260,13 @@ function Pressable(props: Props, forwardedRef): React.Node {
237260
[
238261
android_disableSound,
239262
android_rippleConfig,
263+
delayHoverIn,
264+
delayHoverOut,
240265
delayLongPress,
241266
disabled,
242267
hitSlop,
243-
onMouseEnter, // [TODO(macOS GH#774)
244-
onMouseLeave, // ]TODO(macOS GH#774)
268+
onHoverIn,
269+
onHoverOut,
245270
onLongPress,
246271
onPress,
247272
onPressIn,

packages/rn-tester/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ SPEC CHECKSUMS:
508508
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
509509
DoubleConversion: 0ea4559a49682230337df966e735d6cc7760108e
510510
FBLazyVector: c5de505838fe71cd49ad8a0a647e9e506ba0fccf
511-
FBReactNativeSpec: 84b776b54e14dec317a4525eed6e37a7de350c4b
511+
FBReactNativeSpec: fb1b52da62c8f1cc4c1bcc5e30d13e9ba6009d99
512512
Flipper: d3da1aa199aad94455ae725e9f3aa43f3ec17021
513513
Flipper-DoubleConversion: 38631e41ef4f9b12861c67d17cb5518d06badc41
514514
Flipper-Folly: 755929a4f851b2fb2c347d533a23f191b008554c

packages/rn-tester/js/examples/Pressable/PressableExample.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ function PressableFeedbackEvents() {
9999
testID="pressable_feedback_events_button"
100100
accessibilityLabel="pressable feedback events"
101101
accessibilityRole="button"
102-
onMouseEnter={() => appendEvent('mouseEnter')} // [TODO(macOS GH#774)
103-
onMouseLeave={() => appendEvent('mouseLeave')} // ]TODO(macOS GH#774)
102+
onHoverIn={() => appendEvent('hoverIn')} // [TODO(macOS GH#774)
103+
onHoverOut={() => appendEvent('hoverOut')} // ]TODO(macOS GH#774)
104104
onPress={() => appendEvent('press')}
105105
onPressIn={() => appendEvent('pressIn')}
106106
onPressOut={() => appendEvent('pressOut')}

0 commit comments

Comments
 (0)