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(ios): save resizeMode and reapply it when replacing a view #1144

Merged
merged 2 commits into from Dec 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 18 additions & 13 deletions packages/core/ios/LottieReactNative/ContainerView.swift
Expand Up @@ -242,15 +242,8 @@ class ContainerView: RCTView {
}

@objc func setResizeMode(_ resizeMode: String) {
switch resizeMode {
case "cover":
animationView?.contentMode = .scaleAspectFill
case "contain":
animationView?.contentMode = .scaleAspectFit
case "center":
animationView?.contentMode = .center
default: break
}
self.resizeMode = resizeMode
applyContentMode()
}

@objc func setColorFilters(_ newColorFilters: [NSDictionary]) {
Expand Down Expand Up @@ -296,27 +289,39 @@ class ContainerView: RCTView {
func replaceAnimationView(next: LottieAnimationView) {
super.removeReactSubview(animationView)

let contentMode = animationView?.contentMode ?? .scaleAspectFit

animationView = next

animationView?.contentMode = contentMode
animationView?.backgroundBehavior = .pauseAndRestore
animationView?.animationSpeed = speed
animationView?.loopMode = loop
animationView?.frame = self.bounds

addSubview(next)

applyContentMode()
applyColorProperties()
playIfNeeded()

animationView?.animationLoaded = { [weak self] animationView, animation in
animationView?.animationLoaded = { [weak self] _, _ in
guard let self = self else { return }
self.loadedCallback()
}
}

func applyContentMode() {
guard let animationView = animationView else { return }

switch resizeMode {
case "cover":
animationView.contentMode = .scaleAspectFill
case "contain":
animationView.contentMode = .scaleAspectFit
case "center":
animationView.contentMode = .center
default: break
}
}

func applyColorProperties() {
guard let animationView = animationView else { return }

Expand Down