airbnb / lottie-android

Render After Effects animations natively on Android and iOS, Web, and React Native
http://airbnb.io/lottie/
Apache License 2.0
35.02k stars 5.41k forks source link

Animation not updating if we change source json on button click event #2390

Closed maheshmobile closed 1 year ago

maheshmobile commented 1 year ago

On button click action I am changing animation.json file from raw directory.based on if condition, but it is not changing/updating with new setAnimation(expired_dark or expired_light).

Note: I am using only one LottieAnimationView inwhich I am trying to replace dark & light animation json based on button click event

<com.airbnb.lottie.LottieAnimationView android:id="@+id/expired_icon" android:layout_width="40dp" android:layout_height="37dp" android:layout_marginTop="-19dp" app:lottie_autoPlay="true" app:lottie_loop="true" />

I tried by changing app:lottie_autoPlay="true" app:lottie_loop="true" and app:lottie_autoPlay="false" app:lottie_loop="false"

Checklist

  1. using lottie 4.0.0 version.
  2. Android studio, java.
  3. dark mode- https://app.lottiefiles.com/share/7d08a487-5697-4524-bcc2-8035a95f590d
  4. light mode- https://app.lottiefiles.com/share/ec6d617d-fac2-44cc-844c-b11e73cff16b

Java code

**LottieAnimationView sanimationView_status = view.findViewById(R.id.expired_icon); animationView_status.setSafeMode(true);

if(LocaleHelper.getModeTheme_Pref(mainActivity)) {
    animationView_status.setAnimation(R.raw.expired_dark);

} else {
    animationView_status.setAnimation(R.raw.expired_light);
}
animationView_status.setRepeatCount(LottieDrawable.INFINITE);
animationView_status.playAnimation();**

Always shows initial mapped json animation, example if i luanch app with dark mode it shows expired_dark animation, if it light mode it shows expired_light animation but if I chnage by click action not chnaging.

gpeal commented 1 year ago

I don't see a click handler in your sample code. Would it be possible to attach a sample project? I've changed animations from click handlers many times and it should work.

gpeal commented 1 year ago

I'm going to close this due to lack of activity. If this is still an issue, feel free to reopen with a repro project.