Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
valeriiamykhalova opened this issue Apr 3, 2023 · 1 comment
Assignees

Comments

@valeriiamykhalova
Copy link

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"

@TheRogue76 TheRogue76 self-assigned this Jan 21, 2024
@TheRogue76
Copy link
Collaborator

TheRogue76 commented Jan 21, 2024

I feel like the Android API is not working correctly in this case. We have a method called reset which should be used for these cases. play should simply continue playing, not reset anything. @matinzd ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants