diff --git a/packages/react-native/Libraries/Components/Pressable/Pressable.js b/packages/react-native/Libraries/Components/Pressable/Pressable.js index a0c4258ba30fb7..e72e22c525786f 100644 --- a/packages/react-native/Libraries/Components/Pressable/Pressable.js +++ b/packages/react-native/Libraries/Components/Pressable/Pressable.js @@ -20,11 +20,11 @@ import type { AccessibilityState, AccessibilityValue, } from '../View/ViewAccessibility'; -import type {HoverEffect} from '../View/ViewPropTypes'; 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, { @@ -33,18 +33,12 @@ import useAndroidRippleForView, { import * as React from 'react'; import {useMemo, useRef, useState} from 'react'; -const defaultHoverEffect: HoverEffect = 'highlight'; - type ViewStyleProp = $ElementType, 'style'>; export type StateCallbackType = $ReadOnly<{| pressed: boolean, |}>; -type VisionOSProps = $ReadOnly<{| - visionos_hoverEffect?: ?HoverEffect, -|}>; - type Props = $ReadOnly<{| /** * Accessibility. @@ -200,10 +194,6 @@ type Props = $ReadOnly<{| * https://github.com/facebook/react-native/issues/34424 */ 'aria-label'?: ?string, - /** - * Props needed for visionOS. - */ - ...VisionOSProps, |}>; /** @@ -243,7 +233,6 @@ function Pressable(props: Props, forwardedRef): React.Node { style, testOnly_pressed, unstable_pressDelay, - visionos_hoverEffect = defaultHoverEffect, ...restProps } = props; @@ -352,15 +341,23 @@ function Pressable(props: Props, forwardedRef): React.Node { {...restPropsWithDefaults} {...eventHandlers} ref={mergedRef} - style={typeof style === 'function' ? style({pressed}) : style} - collapsable={false} - visionos_hoverEffect={visionos_hoverEffect}> + style={[ + styles.pressable, + typeof style === 'function' ? style({pressed}) : style, + ]} + collapsable={false}> {typeof children === 'function' ? children({pressed}) : children} {__DEV__ ? : null} ); } +const styles = StyleSheet.create({ + pressable: { + cursor: 'pointer', + }, +}); + function usePressState(forcePressed: boolean): [boolean, (boolean) => void] { const [pressed, setPressed] = useState(false); return [pressed || forcePressed, setPressed]; diff --git a/packages/react-native/Libraries/Components/Pressable/__tests__/__snapshots__/Pressable-test.js.snap b/packages/react-native/Libraries/Components/Pressable/__tests__/__snapshots__/Pressable-test.js.snap index 04af07ed3e54dd..2f9286b98987d6 100644 --- a/packages/react-native/Libraries/Components/Pressable/__tests__/__snapshots__/Pressable-test.js.snap +++ b/packages/react-native/Libraries/Components/Pressable/__tests__/__snapshots__/Pressable-test.js.snap @@ -31,7 +31,14 @@ exports[` should render as expected: should deep render when mocked onResponderTerminate={[Function]} onResponderTerminationRequest={[Function]} onStartShouldSetResponder={[Function]} - visionos_hoverEffect="highlight" + style={ + Array [ + Object { + "cursor": "pointer", + }, + undefined, + ] + } > @@ -68,7 +75,14 @@ exports[` 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, + ] + } > @@ -117,7 +131,14 @@ exports[` should be disabled when disabled is true: onResponderTerminate={[Function]} onResponderTerminationRequest={[Function]} onStartShouldSetResponder={[Function]} - visionos_hoverEffect="highlight" + style={ + Array [ + Object { + "cursor": "pointer", + }, + undefined, + ] + } > @@ -154,7 +175,14 @@ exports[` should be disabled when disabled is true: onResponderTerminate={[Function]} onResponderTerminationRequest={[Function]} onStartShouldSetResponder={[Function]} - visionos_hoverEffect="highlight" + style={ + Array [ + Object { + "cursor": "pointer", + }, + undefined, + ] + } > @@ -207,7 +235,14 @@ exports[` should be disable onResponderTerminate={[Function]} onResponderTerminationRequest={[Function]} onStartShouldSetResponder={[Function]} - visionos_hoverEffect="highlight" + style={ + Array [ + Object { + "cursor": "pointer", + }, + undefined, + ] + } > @@ -244,7 +279,14 @@ exports[` should be disable onResponderTerminate={[Function]} onResponderTerminationRequest={[Function]} onStartShouldSetResponder={[Function]} - visionos_hoverEffect="highlight" + style={ + Array [ + Object { + "cursor": "pointer", + }, + undefined, + ] + } > @@ -299,7 +341,14 @@ exports[` shou onResponderTerminate={[Function]} onResponderTerminationRequest={[Function]} onStartShouldSetResponder={[Function]} - visionos_hoverEffect="highlight" + style={ + Array [ + Object { + "cursor": "pointer", + }, + undefined, + ] + } > @@ -336,7 +385,14 @@ exports[` shou onResponderTerminate={[Function]} onResponderTerminationRequest={[Function]} onStartShouldSetResponder={[Function]} - visionos_hoverEffect="highlight" + style={ + Array [ + Object { + "cursor": "pointer", + }, + undefined, + ] + } > @@ -399,7 +455,14 @@ exports[` sh onResponderTerminate={[Function]} onResponderTerminationRequest={[Function]} onStartShouldSetResponder={[Function]} - visionos_hoverEffect="highlight" + style={ + Array [ + Object { + "cursor": "pointer", + }, + undefined, + ] + } > @@ -436,7 +499,14 @@ exports[` sh onResponderTerminate={[Function]} onResponderTerminationRequest={[Function]} onStartShouldSetResponder={[Function]} - visionos_hoverEffect="highlight" + style={ + Array [ + Object { + "cursor": "pointer", + }, + undefined, + ] + } > diff --git a/packages/react-native/Libraries/Components/Touchable/TouchableHighlight.js b/packages/react-native/Libraries/Components/Touchable/TouchableHighlight.js index f434c3093354e2..60231d8704222f 100644 --- a/packages/react-native/Libraries/Components/Touchable/TouchableHighlight.js +++ b/packages/react-native/Libraries/Components/Touchable/TouchableHighlight.js @@ -9,7 +9,6 @@ */ import type {ColorValue} from '../../StyleSheet/StyleSheet'; -import type {HoverEffect} from '../View/ViewPropTypes'; import typeof TouchableWithoutFeedback from './TouchableWithoutFeedback'; import View from '../../Components/View/View'; @@ -33,15 +32,10 @@ type IOSProps = $ReadOnly<{| hasTVPreferredFocus?: ?boolean, |}>; -type VisionOSProps = $ReadOnly<{| - hoverEffect?: ?HoverEffect, -|}>; - type Props = $ReadOnly<{| ...React.ElementConfig, ...AndroidProps, ...IOSProps, - ...VisionOSProps, activeOpacity?: ?number, underlayColor?: ?ColorValue, @@ -335,10 +329,13 @@ class TouchableHighlight extends React.Component { 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} @@ -347,7 +344,6 @@ class TouchableHighlight extends React.Component { nextFocusLeft={this.props.nextFocusLeft} nextFocusRight={this.props.nextFocusRight} nextFocusUp={this.props.nextFocusUp} - visionos_hoverEffect={this.props.hoverEffect} focusable={ this.props.focusable !== false && this.props.onPress !== undefined } @@ -386,6 +382,12 @@ class TouchableHighlight extends React.Component { } } +const styles = StyleSheet.create({ + touchable: { + cursor: 'pointer', + }, +}); + const Touchable: React.AbstractComponent< $ReadOnly<$Diff|}>>, React.ElementRef, diff --git a/packages/react-native/Libraries/Components/Touchable/TouchableOpacity.d.ts b/packages/react-native/Libraries/Components/Touchable/TouchableOpacity.d.ts index f9b2e6a07f0df4..37c4ce6df43e4c 100644 --- a/packages/react-native/Libraries/Components/Touchable/TouchableOpacity.d.ts +++ b/packages/react-native/Libraries/Components/Touchable/TouchableOpacity.d.ts @@ -11,7 +11,7 @@ import type * as React from 'react'; import {Constructor} from '../../../types/private/Utilities'; import {TimerMixin} from '../../../types/private/TimerMixin'; import {NativeMethods} from '../../../types/public/ReactNativeTypes'; -import {HoverEffect, TVParallaxProperties} from '../View/ViewPropTypes'; +import {TVParallaxProperties} from '../View/ViewPropTypes'; import {TouchableMixin} from './Touchable'; import {TouchableWithoutFeedbackProps} from './TouchableWithoutFeedback'; @@ -86,11 +86,6 @@ export interface TouchableOpacityProps * @platform android */ tvParallaxProperties?: TVParallaxProperties | undefined; - - /** - * Hover style to apply to the view. Only supported on visionOS. - */ - visionos_hoverEffect?: HoverEffect | undefined; } /** diff --git a/packages/react-native/Libraries/Components/Touchable/TouchableOpacity.js b/packages/react-native/Libraries/Components/Touchable/TouchableOpacity.js index 1805226d8632ac..70538a9a2a0d7c 100644 --- a/packages/react-native/Libraries/Components/Touchable/TouchableOpacity.js +++ b/packages/react-native/Libraries/Components/Touchable/TouchableOpacity.js @@ -9,7 +9,6 @@ */ import type {ViewStyleProp} from '../../StyleSheet/StyleSheet'; -import type {HoverEffect} from '../View/ViewPropTypes'; import typeof TouchableWithoutFeedback from './TouchableWithoutFeedback'; import Animated from '../../Animated/Animated'; @@ -19,11 +18,10 @@ 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'; -const defaultHoverEffect: HoverEffect = 'highlight'; - type TVProps = $ReadOnly<{| hasTVPreferredFocus?: ?boolean, nextFocusDown?: ?number, @@ -33,14 +31,9 @@ type TVProps = $ReadOnly<{| nextFocusUp?: ?number, |}>; -type VisionOSProps = $ReadOnly<{| - visionos_hoverEffect?: ?HoverEffect, -|}>; - type Props = $ReadOnly<{| ...React.ElementConfig, ...TVProps, - ...VisionOSProps, activeOpacity?: ?number, style?: ?ViewStyleProp, @@ -138,10 +131,6 @@ type State = $ReadOnly<{| * */ class TouchableOpacity extends React.Component { - static defaultProps: {|visionos_hoverEffect: HoverEffect|} = { - visionos_hoverEffect: defaultHoverEffect, - }; - state: State = { anim: new Animated.Value(this._getChildStyleOpacityWithDefault()), pressability: new Pressability(this._createPressabilityConfig()), @@ -287,7 +276,7 @@ class TouchableOpacity extends React.Component { 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} @@ -298,7 +287,6 @@ class TouchableOpacity extends React.Component { nextFocusUp={this.props.nextFocusUp} hasTVPreferredFocus={this.props.hasTVPreferredFocus} hitSlop={this.props.hitSlop} - visionos_hoverEffect={this.props.visionos_hoverEffect} focusable={ this.props.focusable !== false && this.props.onPress !== undefined } @@ -336,6 +324,12 @@ class TouchableOpacity extends React.Component { } } +const styles = StyleSheet.create({ + touchable: { + cursor: 'pointer', + }, +}); + const Touchable: React.AbstractComponent< Props, React.ElementRef, diff --git a/packages/react-native/Libraries/Components/Touchable/__tests__/__snapshots__/TouchableHighlight-test.js.snap b/packages/react-native/Libraries/Components/Touchable/__tests__/__snapshots__/TouchableHighlight-test.js.snap index 35c845e97493fc..f26560d45d738a 100644 --- a/packages/react-native/Libraries/Components/Touchable/__tests__/__snapshots__/TouchableHighlight-test.js.snap +++ b/packages/react-native/Libraries/Components/Touchable/__tests__/__snapshots__/TouchableHighlight-test.js.snap @@ -19,7 +19,14 @@ exports[`TouchableHighlight renders correctly 1`] = ` onResponderTerminate={[Function]} onResponderTerminationRequest={[Function]} onStartShouldSetResponder={[Function]} - style={Object {}} + style={ + Array [ + Object { + "cursor": "pointer", + }, + Object {}, + ] + } > Touchable @@ -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, + ] + } > @@ -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, + ] + } > @@ -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, + ] + } > @@ -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, + ] + } > @@ -168,6 +207,14 @@ exports[`TouchableHighlight with disabled state should overwrite accessibilitySt onResponderTerminate={[Function]} onResponderTerminationRequest={[Function]} onStartShouldSetResponder={[Function]} + style={ + Array [ + Object { + "cursor": "pointer", + }, + undefined, + ] + } > diff --git a/packages/react-native/Libraries/Components/Touchable/__tests__/__snapshots__/TouchableOpacity-test.js.snap b/packages/react-native/Libraries/Components/Touchable/__tests__/__snapshots__/TouchableOpacity-test.js.snap index 782187fd0891c4..ca634909ca5afc 100644 --- a/packages/react-native/Libraries/Components/Touchable/__tests__/__snapshots__/TouchableOpacity-test.js.snap +++ b/packages/react-native/Libraries/Components/Touchable/__tests__/__snapshots__/TouchableOpacity-test.js.snap @@ -31,10 +31,10 @@ exports[`TouchableOpacity renders correctly 1`] = ` onStartShouldSetResponder={[Function]} style={ Object { + "cursor": "pointer", "opacity": 1, } } - visionos_hoverEffect="highlight" > Touchable @@ -73,10 +73,10 @@ exports[`TouchableOpacity renders in disabled state when a disabled prop is pass onStartShouldSetResponder={[Function]} style={ Object { + "cursor": "pointer", "opacity": 1, } } - visionos_hoverEffect="highlight" > Touchable @@ -115,10 +115,10 @@ exports[`TouchableOpacity renders in disabled state when a key disabled in acces onStartShouldSetResponder={[Function]} style={ Object { + "cursor": "pointer", "opacity": 1, } } - visionos_hoverEffect="highlight" > Touchable diff --git a/packages/react-native/Libraries/Components/View/ViewNativeComponent.js b/packages/react-native/Libraries/Components/View/ViewNativeComponent.js index 0049806e12cdff..df119f6c5edf5d 100644 --- a/packages/react-native/Libraries/Components/View/ViewNativeComponent.js +++ b/packages/react-native/Libraries/Components/View/ViewNativeComponent.js @@ -103,9 +103,6 @@ export const __INTERNAL_VIEW_CONFIG: PartialViewConfig = } : { uiViewClassName: 'RCTView', - validAttributes: { - visionos_hoverEffect: true, - }, }; const ViewNativeComponent: HostComponent = diff --git a/packages/react-native/Libraries/Components/View/ViewPropTypes.d.ts b/packages/react-native/Libraries/Components/View/ViewPropTypes.d.ts index 3fe95f21e74e5e..20ff434f97b879 100644 --- a/packages/react-native/Libraries/Components/View/ViewPropTypes.d.ts +++ b/packages/react-native/Libraries/Components/View/ViewPropTypes.d.ts @@ -16,8 +16,6 @@ import {LayoutChangeEvent, PointerEvents} from '../../Types/CoreEventTypes'; import {Touchable} from '../Touchable/Touchable'; import {AccessibilityProps} from './ViewAccessibility'; -export type HoverEffect = 'lift' | 'highlight'; - export type TVParallaxProperties = { /** * If true, parallax effects are enabled. Defaults to true. @@ -124,10 +122,6 @@ export interface ViewPropsIOS extends TVViewPropsIOS { * Test and measure when using this property. */ shouldRasterizeIOS?: boolean | undefined; - /** - * Hover style to apply to the view. Only supported on visionOS. - */ - visionos_hoverEffect?: HoverEffect | undefined; } export interface ViewPropsAndroid { diff --git a/packages/react-native/Libraries/Components/View/ViewPropTypes.js b/packages/react-native/Libraries/Components/View/ViewPropTypes.js index 8991759e403cb9..692410cd89d176 100644 --- a/packages/react-native/Libraries/Components/View/ViewPropTypes.js +++ b/packages/react-native/Libraries/Components/View/ViewPropTypes.js @@ -263,8 +263,6 @@ type AndroidDrawableRipple = $ReadOnly<{| rippleRadius?: ?number, |}>; -export type HoverEffect = 'lift' | 'highlight'; - type AndroidDrawable = AndroidDrawableThemeAttr | AndroidDrawableRipple; type AndroidViewProps = $ReadOnly<{| @@ -453,11 +451,6 @@ type IOSViewProps = $ReadOnly<{| * See https://reactnative.dev/docs/view#shouldrasterizeios */ shouldRasterizeIOS?: ?boolean, - - /** - * Hover style to apply to the view. Only supported on visionOS. - */ - visionos_hoverEffect?: ?HoverEffect, |}>; export type ViewProps = $ReadOnly<{| diff --git a/packages/react-native/Libraries/Components/__tests__/__snapshots__/Button-test.js.snap b/packages/react-native/Libraries/Components/__tests__/__snapshots__/Button-test.js.snap index e6622925664273..a3efb80e477bfc 100644 --- a/packages/react-native/Libraries/Components/__tests__/__snapshots__/Button-test.js.snap +++ b/packages/react-native/Libraries/Components/__tests__/__snapshots__/Button-test.js.snap @@ -32,10 +32,10 @@ exports[`