Skip to content

Commit

Permalink
fix(ios): save resizeMode and reapply it when replacing a view
Browse files Browse the repository at this point in the history
  • Loading branch information
hardworker committed Dec 29, 2023
1 parent 9862fda commit 9aaf79a
Showing 1 changed file with 18 additions and 13 deletions.
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

0 comments on commit 9aaf79a

Please sign in to comment.