Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Cannot restart playing animation from the beginning until it's finished (on IOS) #1004

@valeriiamykhalova

Description

@valeriiamykhalova

Description

Animation does not restart immediately on calling animationRef.current?.play(). It works as expected on Android, but not on IOS

Steps to Reproduce

  1. Download free animation https://lottiefiles.com/141221-egg-roll
  2. 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"

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions