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

Fix issue where LottieAnimationLayer.pause() didn't update currentPlaybackMode #2188

Merged
merged 1 commit into from
Sep 14, 2023

Conversation

calda
Copy link
Member

@calda calda commented Sep 14, 2023

This PR fixes an issue where LottieAnimationLayer.pause() didn't update currentPlaybackMode.

I was writing the announcement for Lottie 4.3.0, and included this sample code:

// The Lottie animation is controlled by this SwiftUI state
@State var playbackMode = LottiePlaybackMode.pause

var body: some View {
  HStack {
    LottieView(animation: .named("HeartAnimation"))
      .play(playbackMode)
      .animationDidFinish { _ in
        playbackMode = .pause
      }
  
    // When the button is pressed, trigger the animation to start playing from the beginning
    Button {
      playbackMode = .fromProgress(0, toProgress: 1, loopMode: .playOnce)
    } label: {
      Image(systemName: "play.fill")
    }
  }
}

When testing that on master, setting playbackMode = .fromProgress(0, toProgress: 1, loopMode: .playOnce) didn't cause the animation to start playing again.

This was because LottieAnimationLayer.pause() wasn't updating currentPlaybackMode, so the value of currentPlaybackMode was still .fromProgress(0, toProgress: 1, loopMode: .playOnce). That caused subsequent calls to be ignored.

Before After
2023-09-14 12 07 47 2023-09-14 12 08 38

@calda calda enabled auto-merge (squash) September 14, 2023 19:26
@calda calda disabled auto-merge September 14, 2023 19:55
@calda calda merged commit 4f8c775 into master Sep 14, 2023
17 checks passed
@calda calda deleted the cal--pause-playback-mode branch September 14, 2023 19:56
iago849 pushed a commit to atteamapps/lottie-ios that referenced this pull request Feb 8, 2024
MoroziOS pushed a commit to MoroziOS/tmg-lottie-ios that referenced this pull request May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants