Skip to content

Commit

Permalink
fix: set cursor pointer by default, update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
okwasniewski committed Feb 23, 2024
1 parent 93c57e8 commit 4f26a6b
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 51 deletions.
16 changes: 11 additions & 5 deletions packages/react-native/Libraries/Components/Pressable/Pressable.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
import {PressabilityDebugView} from '../../Pressability/PressabilityDebug';
import usePressability from '../../Pressability/usePressability';
import {type RectOrSize} from '../../StyleSheet/Rect';
import StyleSheet from '../../StyleSheet/StyleSheet';
import useMergeRefs from '../../Utilities/useMergeRefs';
import View from '../View/View';
import useAndroidRippleForView, {
Expand Down Expand Up @@ -193,10 +194,6 @@ type Props = $ReadOnly<{|
* https://github.com/facebook/react-native/issues/34424
*/
'aria-label'?: ?string,
/**
* Props needed for visionOS.
*/
...VisionOSProps,
|}>;

/**
Expand Down Expand Up @@ -344,14 +341,23 @@ function Pressable(props: Props, forwardedRef): React.Node {
{...restPropsWithDefaults}
{...eventHandlers}
ref={mergedRef}
style={typeof style === 'function' ? style({pressed}) : style}
style={[
styles.pressable,
typeof style === 'function' ? style({pressed}) : style,
]}
collapsable={false}>
{typeof children === 'function' ? children({pressed}) : children}
{__DEV__ ? <PressabilityDebugView color="red" hitSlop={hitSlop} /> : null}
</View>
);
}

const styles = StyleSheet.create({
pressable: {
cursor: 'pointer',
},
});

function usePressState(forcePressed: boolean): [boolean, (boolean) => void] {
const [pressed, setPressed] = useState(false);
return [pressed || forcePressed, setPressed];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ exports[`<Pressable /> should render as expected: should deep render when mocked
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
visionos_hoverEffect="highlight"
style={
Array [
Object {
"cursor": "pointer",
},
undefined,
]
}
>
<View />
</View>
Expand Down Expand Up @@ -68,7 +75,14 @@ exports[`<Pressable /> should render as expected: should deep render when not mo
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
visionos_hoverEffect="highlight"
style={
Array [
Object {
"cursor": "pointer",
},
undefined,
]
}
>
<View />
</View>
Expand Down Expand Up @@ -117,7 +131,14 @@ exports[`<Pressable disabled={true} /> should be disabled when disabled is true:
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
visionos_hoverEffect="highlight"
style={
Array [
Object {
"cursor": "pointer",
},
undefined,
]
}
>
<View />
</View>
Expand Down Expand Up @@ -154,7 +175,14 @@ exports[`<Pressable disabled={true} /> should be disabled when disabled is true:
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
visionos_hoverEffect="highlight"
style={
Array [
Object {
"cursor": "pointer",
},
undefined,
]
}
>
<View />
</View>
Expand Down Expand Up @@ -207,7 +235,14 @@ exports[`<Pressable disabled={true} accessibilityState={{}} /> should be disable
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
visionos_hoverEffect="highlight"
style={
Array [
Object {
"cursor": "pointer",
},
undefined,
]
}
>
<View />
</View>
Expand Down Expand Up @@ -244,7 +279,14 @@ exports[`<Pressable disabled={true} accessibilityState={{}} /> should be disable
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
visionos_hoverEffect="highlight"
style={
Array [
Object {
"cursor": "pointer",
},
undefined,
]
}
>
<View />
</View>
Expand Down Expand Up @@ -299,7 +341,14 @@ exports[`<Pressable disabled={true} accessibilityState={{checked: true}} /> shou
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
visionos_hoverEffect="highlight"
style={
Array [
Object {
"cursor": "pointer",
},
undefined,
]
}
>
<View />
</View>
Expand Down Expand Up @@ -336,7 +385,14 @@ exports[`<Pressable disabled={true} accessibilityState={{checked: true}} /> shou
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
visionos_hoverEffect="highlight"
style={
Array [
Object {
"cursor": "pointer",
},
undefined,
]
}
>
<View />
</View>
Expand Down Expand Up @@ -399,7 +455,14 @@ exports[`<Pressable disabled={true} accessibilityState={{disabled: false}} /> sh
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
visionos_hoverEffect="highlight"
style={
Array [
Object {
"cursor": "pointer",
},
undefined,
]
}
>
<View />
</View>
Expand Down Expand Up @@ -436,7 +499,14 @@ exports[`<Pressable disabled={true} accessibilityState={{disabled: false}} /> sh
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
visionos_hoverEffect="highlight"
style={
Array [
Object {
"cursor": "pointer",
},
undefined,
]
}
>
<View />
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ type Props = $ReadOnly<{|
...React.ElementConfig<TouchableWithoutFeedback>,
...AndroidProps,
...IOSProps,
...VisionOSProps,

activeOpacity?: ?number,
underlayColor?: ?ColorValue,
Expand Down Expand Up @@ -330,10 +329,13 @@ class TouchableHighlight extends React.Component<Props, State> {
accessibilityElementsHidden={
this.props['aria-hidden'] ?? this.props.accessibilityElementsHidden
}
style={StyleSheet.compose(
this.props.style,
this.state.extraStyles?.underlay,
)}
style={[
styles.touchable,
StyleSheet.compose(
this.props.style,
this.state.extraStyles?.underlay,
),
]}
onLayout={this.props.onLayout}
hitSlop={this.props.hitSlop}
hasTVPreferredFocus={this.props.hasTVPreferredFocus}
Expand Down Expand Up @@ -380,6 +382,12 @@ class TouchableHighlight extends React.Component<Props, State> {
}
}

const styles = StyleSheet.create({
touchable: {
cursor: 'pointer',
},
});

const Touchable: React.AbstractComponent<
$ReadOnly<$Diff<Props, {|hostRef: React.Ref<typeof View>|}>>,
React.ElementRef<typeof View>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Pressability, {
} from '../../Pressability/Pressability';
import {PressabilityDebugView} from '../../Pressability/PressabilityDebug';
import flattenStyle from '../../StyleSheet/flattenStyle';
import StyleSheet from '../../StyleSheet/StyleSheet';
import Platform from '../../Utilities/Platform';
import * as React from 'react';

Expand All @@ -33,7 +34,6 @@ type TVProps = $ReadOnly<{|
type Props = $ReadOnly<{|
...React.ElementConfig<TouchableWithoutFeedback>,
...TVProps,
...VisionOSProps,

activeOpacity?: ?number,
style?: ?ViewStyleProp,
Expand Down Expand Up @@ -276,7 +276,7 @@ class TouchableOpacity extends React.Component<Props, State> {
accessibilityElementsHidden={
this.props['aria-hidden'] ?? this.props.accessibilityElementsHidden
}
style={[this.props.style, {opacity: this.state.anim}]}
style={[styles.touchable, this.props.style, {opacity: this.state.anim}]}
nativeID={this.props.id ?? this.props.nativeID}
testID={this.props.testID}
onLayout={this.props.onLayout}
Expand Down Expand Up @@ -324,6 +324,12 @@ class TouchableOpacity extends React.Component<Props, State> {
}
}

const styles = StyleSheet.create({
touchable: {
cursor: 'pointer',
},
});

const Touchable: React.AbstractComponent<
Props,
React.ElementRef<typeof Animated.View>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ exports[`TouchableHighlight renders correctly 1`] = `
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={Object {}}
style={
Array [
Object {
"cursor": "pointer",
},
Object {},
]
}
>
<Text>
Touchable
Expand Down Expand Up @@ -51,6 +58,14 @@ exports[`TouchableHighlight with disabled state should be disabled when disabled
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
"cursor": "pointer",
},
undefined,
]
}
>
<View />
</View>
Expand Down Expand Up @@ -80,6 +95,14 @@ exports[`TouchableHighlight with disabled state should be disabled when disabled
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
"cursor": "pointer",
},
undefined,
]
}
>
<View />
</View>
Expand Down Expand Up @@ -109,6 +132,14 @@ exports[`TouchableHighlight with disabled state should disable button when acces
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
"cursor": "pointer",
},
undefined,
]
}
>
<View />
</View>
Expand Down Expand Up @@ -139,6 +170,14 @@ exports[`TouchableHighlight with disabled state should keep accessibilityState w
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
"cursor": "pointer",
},
undefined,
]
}
>
<View />
</View>
Expand Down Expand Up @@ -168,6 +207,14 @@ exports[`TouchableHighlight with disabled state should overwrite accessibilitySt
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Array [
Object {
"cursor": "pointer",
},
undefined,
]
}
>
<View />
</View>
Expand Down
Loading

0 comments on commit 4f26a6b

Please sign in to comment.