dont scale in pressable w/ reduced motion (#5697)

This commit is contained in:
Hailey
2024-10-10 19:21:04 -07:00
committed by GitHub
parent 32bf38940d
commit 9176a8ff64
+4 -1
View File
@@ -4,6 +4,7 @@ import Animated, {
cancelAnimation, cancelAnimation,
runOnJS, runOnJS,
useAnimatedStyle, useAnimatedStyle,
useReducedMotion,
useSharedValue, useSharedValue,
withTiming, withTiming,
} from 'react-native-reanimated' } from 'react-native-reanimated'
@@ -26,6 +27,8 @@ export function PressableScale({
targetScale?: number targetScale?: number
style?: StyleProp<ViewStyle> style?: StyleProp<ViewStyle>
} & Exclude<PressableProps, 'onPressIn' | 'onPressOut' | 'style'>) { } & Exclude<PressableProps, 'onPressIn' | 'onPressOut' | 'style'>) {
const reducedMotion = useReducedMotion()
const scale = useSharedValue(1) const scale = useSharedValue(1)
const animatedStyle = useAnimatedStyle(() => ({ const animatedStyle = useAnimatedStyle(() => ({
@@ -51,7 +54,7 @@ export function PressableScale({
cancelAnimation(scale) cancelAnimation(scale)
scale.value = withTiming(1, {duration: 100}) scale.value = withTiming(1, {duration: 100})
}} }}
style={[animatedStyle, style]} style={[!reducedMotion && animatedStyle, style]}
{...rest}> {...rest}>
{children} {children}
</AnimatedPressable> </AnimatedPressable>