dont scale in pressable w/ reduced motion (#5697)
This commit is contained in:
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user