Skip to content

Commit 18757ce

Browse files
authored
Revert FHL changes to useAsPressable (#1098)
* revert changes in useAsPressable * podfile * Change files * remove unnecessary import
1 parent 9be422a commit 18757ce

File tree

3 files changed

+15
-26
lines changed

3 files changed

+15
-26
lines changed

apps/macos/src/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,4 +491,4 @@ SPEC CHECKSUMS:
491491

492492
PODFILE CHECKSUM: b54fe60c3ce918d2e858b86629d2094398e73914
493493

494-
COCOAPODS: 1.10.2
494+
COCOAPODS: 1.11.2
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "revert changes in useAsPressable",
4+
"packageName": "@fluentui-react-native/interactive-hooks",
5+
"email": "sanajmi@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

packages/utils/interactive-hooks/src/useAsPressable.ts

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import { PressableProps } from 'react-native';
3-
import { PressableFocusProps, PressableHoverProps, PressableHoverEventProps, PressablePressProps } from './Pressability/Pressability.types';
3+
import { PressableFocusProps, PressableHoverProps, PressablePressProps } from './Pressability/Pressability.types';
44
import {
55
IPressableHooks,
66
IWithPressableOptions,
@@ -16,16 +16,10 @@ import { usePressability } from './usePressability';
1616
/**
1717
* hover specific state and callback helper
1818
*/
19-
function useHoverHelper(props: PressableHoverProps): [PressableHoverEventProps, IHoverState] {
19+
function useHoverHelper(props: PressableHoverProps): [PressableHoverProps, IHoverState] {
2020
const [hoverState, setHoverState] = React.useState({ hovered: false });
2121

22-
// https://github.com/facebook/react-native/issues/32406
23-
// Pressability exposes onHoverIn & onHoverOut, and converts them into onMouseEnter/onMouseLeave event handlers
24-
// passed into an inner <View> component. However,Pressable does not expose onHoverIn/onHoverOut as props. Our
25-
// desktop ports do expose onMouseEnter & onMouseLeave as event handlers on View though. As a workaround, let's
26-
// have our public API take in onHoverIn & onHoverOut as props, but pass them as onMouseEnter/onMouseLeave
27-
28-
const onMouseEnter = React.useCallback(
22+
const onHoverIn = React.useCallback(
2923
(e) => {
3024
setHoverState({ hovered: true });
3125
if (props.onHoverIn) {
@@ -35,7 +29,7 @@ function useHoverHelper(props: PressableHoverProps): [PressableHoverEventProps,
3529
[setHoverState, props.onHoverIn],
3630
);
3731

38-
const onMouseLeave = React.useCallback(
32+
const onHoverOut = React.useCallback(
3933
(e) => {
4034
setHoverState({ hovered: false });
4135
if (props.onHoverOut) {
@@ -44,7 +38,7 @@ function useHoverHelper(props: PressableHoverProps): [PressableHoverEventProps,
4438
},
4539
[setHoverState, props.onHoverOut],
4640
);
47-
return [{ onMouseEnter, onMouseLeave }, hoverState];
41+
return [{ onHoverIn, onHoverOut }, hoverState];
4842
}
4943

5044
/**
@@ -132,12 +126,8 @@ export function usePressState<T extends object>(props: IWithPressableOptions<T>)
132126
*/
133127
// eslint-disable-next-line @typescript-eslint/ban-types
134128
export function useHoverState<T extends object>(props: IWithPressableOptions<T>): [IWithPressableEvents<T>, IHoverState] {
135-
// https://github.com/facebook/react-native/issues/32406
136-
// Pressability takes in onHoverIn & onHoverOut, while useHoverHelper returns onMouseEnter & onMouseLeave.
137-
// Lets be sure to pass these props properly into usePressability.
138129
const [hoverProps, hoverState] = useHoverHelper(props);
139-
const { onMouseEnter, onMouseLeave, ...restHoverProps } = hoverProps;
140-
return [{ ...props, ...usePressability({ ...props, onHoverIn: onMouseEnter, onHoverOut: onMouseLeave, ...restHoverProps }) }, hoverState];
130+
return [{ ...props, ...usePressability({ ...props, ...hoverProps }) }, hoverState];
141131
}
142132

143133
/**
@@ -152,16 +142,8 @@ export function useAsPressable<T extends object>(props: IWithPressableOptions<T>
152142
const [hoverProps, hoverState] = useHoverHelper(props);
153143
const [focusProps, focusState] = useFocusHelper(props);
154144
const [pressProps, pressState] = usePressHelper(props);
145+
const pressabilityProps = usePressability({ ...props, ...hoverProps, ...focusProps, ...pressProps });
155146

156-
// https://github.com/facebook/react-native/issues/32406
157-
// Convert onMouseEnter & onMouseLeave back into onHoverIn & onHoverOut before passing into usePressability
158-
const pressabilityProps = usePressability({
159-
onHoverIn: hoverProps.onMouseEnter,
160-
onHoverOut: hoverProps.onMouseLeave,
161-
...focusProps,
162-
...pressProps,
163-
...props,
164-
});
165147
return {
166148
props: { ...props, ...pressabilityProps },
167149
state: { ...hoverState, ...focusState, ...pressState },

0 commit comments

Comments
 (0)