[2.3] Toggling `withTiming` on/off doesn't animate
See original GitHub issueDescription
This code never animates:
const style = useAnimatedStyle(() => ({
width: isActive.value ? 100 : withTiming(300)
}))
Instead, it always snaps directly between 100 and 300, without an animation.
Expected behavior
When active, this should snap to 100. When inactive, it should do a timing animation to 300. This worked on 2.2.
Actual behavior & steps to reproduce
The animation snaps to 300 when inactive. It doesn’t animate.
This solves it:
const style = useAnimatedStyle(() => ({
width: withTiming(isActive.value ? 100 : 300, { duration: isActive.value ? 0 : 250 })
}))
But it shouldn’t be necessary.
Snack or minimal code example
View Code
import React from 'react'
import { Pressable, StyleSheet } from 'react-native'
import Animated, {
useAnimatedStyle,
useSharedValue,
withTiming,
} from 'react-native-reanimated'
export default function HelloWorld() {
const pressed = useSharedValue(false)
const style = useAnimatedStyle(() => {
return {
// this never animates
width: pressed.value ? 100 : withTiming(300),
// this does animate
// width: withTiming(pressed.value ? 100 : 300, { duration: pressed.value ? 0 : 250 })
}
})
return (
<Pressable
onPressIn={() => (pressed.value = true)}
style={styles.container}
onPressOut={() => (pressed.value = false)}
>
<Animated.View style={[styles.shape, style]} />
</Pressable>
)
}
const styles = StyleSheet.create({
shape: {
justifyContent: 'center',
height: 250,
width: 250,
borderRadius: 25,
marginRight: 10,
backgroundColor: 'black',
},
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'row',
backgroundColor: '#9c1aff',
},
})
Video
https://www.loom.com/share/42aa2a930b0f440692cc6d1e2d86375b
Package versions
- React Native: 0.63.4
- React Native Reanimated: 2.3.2
- NodeJS:
- Xcode:
- Java & Gradle:
Affected platforms
- Android
- iOS
- Web
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
withTiming | React Native Reanimated - Software Mansion
Returns This method returns an animation object. It can be either assigned directly to a Shared Value or can be used as a...
Read more >HydroDAS & MiniDAS Oceanographic Data Acquisition Systems ...
allows it to operate at somewhat higher data rates, but it does not work well ... configuration, turning On/Off power outputs & serial...
Read more >MCIMX6QP7CVT8AB MCIMX6DP7CVT8AB NXP USA Datasheet
The temperature read out does not reflect case or ambient temperature. ... keeping real time and other data on OFF state. ... would...
Read more >u-blox 6 Receiver Description and Protocol Specification - StudyLib
2 2.3 Navigation Output Filters . ... 18 9.3.1.1 ON/OFF operation - long update period . ... The grid offset does not work...
Read more >ZigBee Cluster Library (for ZigBee 3.0) User Guide - NXP
15.2 On/Off Switch Config Cluster Structure and Attribute ... Section 2.3.2) - if the attribute does not exist on the.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks for the report 🙌 I resolved the issue in linked PR.
Same here. This has prevented us from upgrading, but we’re also facing an issue where
measuredoesn’t work in iOS modals in 2.2, but is fixed in 2.3…