lottie-react-native icon indicating copy to clipboard operation
lottie-react-native copied to clipboard

animation reset to first frame when app resume from background

Open sbin1211 opened this issue 3 years ago • 17 comments

Description

at ios, after animation finished, when app goto background then resume, the animation reset to first frame not end of frame. this issue accure at 5.0.0, 5.0.1, it's ok before 5.0.0

Steps to Reproduce

https://user-images.githubusercontent.com/22540308/145149332-3ff9113d-c39a-4d73-8f58-58ea9c779c83.mp4

Expected behavior: animation should stay at last of frame.

Actual behavior: animation reset to first frame.

Versions

[email protected] [email protected] system

sbin1211 avatar Dec 08 '21 04:12 sbin1211

@emilioicai could you have a look. thanks.

sbin1211 avatar Dec 08 '21 10:12 sbin1211

This is happening to mine as well, along with looped animations causing the frame to freeze when app resumes from background.

nathanlevitt avatar Jan 01 '22 00:01 nathanlevitt

Having same issue :')

kieranoreilly avatar Jan 21 '22 16:01 kieranoreilly

Same here, any insights?

kyang6 avatar Jan 30 '22 19:01 kyang6

https://github.com/lottie-react-native/lottie-react-native/issues/412 I think related to this issue from a while back

kyang6 avatar Jan 30 '22 19:01 kyang6

I have the same problem. My workaround looks like this:

  useEffect(() => {
    AppState.addEventListener('change', handleAppStateChange);

    return () => {
      AppState.removeEventListener('change', handleAppStateChange);
    };
  }, []);

  function handleAppStateChange(nextAppState: AppStateStatus) {
    if (nextAppState === 'active') {
      lottieRef.current!.play(75, 75);
    }
  }

Livijn avatar Feb 21 '22 21:02 Livijn

Happening for us on iOS, 5.0.1

cam-shaw avatar Mar 08 '22 11:03 cam-shaw

Hello, this is also happening for us. Android is fine.

We're just upgraded to: "react-native": "0.66.4", "lottie-ios": "3.2.3", "lottie-react-native": "5.0.1",

It's only happened with the upgrade but we can't downgrade from RN66 and lottie-react-native installation instructions specify these lottie packages for RN66

@Livijn solution worked a treat for us, we made one amendment though as we were getting a warning Property 'remove' does not exist on type 'AppStateStatic' and so went with

    const subscription = AppState.addEventListener('change', handleAppStateChange);

    return () => {
      return subscription.remove()
    };
  }, []);

Everything else was the same though.

dan-betmate avatar Apr 11 '22 12:04 dan-betmate

I had the same issue and the workaround from @Livijn didn't solve it completely. The animation blinked from the first frame to the last frame. Specifying the property progress={1} helped in my case. Fortunately, autoPlay still works as expected. I use these properties.

<LottieView
  source={require('...')}
  autoPlay
  progress={1}
  loop={false}
/>

branoholy avatar May 13 '22 09:05 branoholy

@branoholy Actually, it seems that setting progress={1} worked. 😮

Livijn avatar May 13 '22 09:05 Livijn

Hi, I'm facing the same bug currently. Do you have some news about it ? progress={1} isn't work for me.

franckmaurin avatar Jun 01 '22 18:06 franckmaurin

@Livijn Thanks

const lottieRef = useRef();

useEffect(() => {
    const sub = AppState.addEventListener("change", handleAppStateChange);

    return () => sub.remove();
  }, []);

  const handleAppStateChange = (nextAppState) => {
    if (nextAppState === "active" && lottieRef.current) {
      lottieRef.current.play();
    }
  };
  
   <LottieView
          ref={lottieRef}
          source={require("./../assets/json/update1.json")}
          autoPlay
          loop
     />

MiteshKalal7 avatar Jul 01 '22 05:07 MiteshKalal7

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 30 '22 17:08 stale[bot]

Commenting to keep this open, as it is still occurring.

ronaldcurtis avatar Aug 30 '22 21:08 ronaldcurtis

I have the same problem. My workaround looks like this:

  useEffect(() => {
    AppState.addEventListener('change', handleAppStateChange);

    return () => {
      AppState.removeEventListener('change', handleAppStateChange);
    };
  }, []);

  function handleAppStateChange(nextAppState: AppStateStatus) {
    if (nextAppState === 'active') {
      lottieRef.current!.play(75, 75);
    }
  }

this is working

nikitph avatar Sep 11 '22 04:09 nikitph

Bump

laffed avatar Sep 15 '22 03:09 laffed

I am facing same issue in android whenever the animation is not visible it doesn't gets completed, i want to get my animation running in background and unable to find any solution for this in Android, can some one please help

vishal-nykaa avatar Sep 20 '22 19:09 vishal-nykaa

bump

as4 avatar Nov 03 '22 13:11 as4

bump

FlushNorris avatar Dec 02 '22 14:12 FlushNorris

Should be possible to set animationView.backgroundBehavior = .pauseAndRestore on lottie-ios via swift, must be possible via react-native as well?! https://github.com/airbnb/lottie-ios/issues/1332

FlushNorris avatar Dec 02 '22 14:12 FlushNorris

Try updating to the latest version, as it is fixed in thie PR. Please reopen the issue if the problem persists.

matinzd avatar Jan 17 '23 11:01 matinzd

It's not fixed in 5.1.4 (the latest version at the moment). Our animations reset when the app goes to background.

as4 avatar Jan 18 '23 13:01 as4

Fixed in https://github.com/lottie-react-native/lottie-react-native/pull/980.

matinzd avatar Jan 31 '23 21:01 matinzd

@matinzd when will you make the new version?

lpatrun avatar Feb 01 '23 07:02 lpatrun

@matinzd when will you make the new version?

Waiting for @emilioicai to approve release script PR. The new release will be under rc tag. Should be out soon.

matinzd avatar Feb 01 '23 07:02 matinzd

Same issue for me in version 5.1.5 🤔

eliasljubec avatar Feb 13 '23 10:02 eliasljubec

Changes are not on the stable branch. Please test it on @next and let us know. @eljubec

matinzd avatar Feb 13 '23 16:02 matinzd