-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Description
Description
Animation does not restart immediately on calling animationRef.current?.play(). It works as expected on Android, but not on IOS
Steps to Reproduce
- Download free animation https://lottiefiles.com/141221-egg-roll
- Copy&paste the following component:
import { useRef, useState } from 'react'
import { View, StyleSheet, Button, Text } from 'react-native'
import LottieView from 'lottie-react-native'
export function Animation() {
const [counter, setCounter] = useState(0)
const animationRef = useRef()
function playAnimation() {
animationRef.current?.play()
setCounter(counter + 1)
}
return (
<View style={styles.container}>
<LottieView
ref={animationRef}
style={styles.animation}
loop={false}
autoPlay={false}
source={require('assets/animations/egg.json')}
/>
<View style={styles.buttonContainer}>
<Button title="Play" onPress={playAnimation} />
<Text style={styles.text}>Pressed {counter} times</Text>
</View>
</View>
)
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'pink',
},
animation: {
flex: 1,
},
buttonContainer: {
position: 'absolute',
left: 0,
right: 0,
bottom: 200,
justifyContent: 'center',
alignItems: 'center',
},
text: {
paddingTop: 24,
fontWeight: '500',
},
})
Expected behavior: I expect the animation to restart immediately after pressing the "Play" button. It works as expected on Android
egg-android.mp4
Actual behavior: Animation does not restart until it reaches the last frame
egg-ios.mp4
Versions
"lottie-ios": "3.4.0"
"lottie-react-native": "^5.1.5"
"react-native": "0.69.5"
ca057