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 3a283dd
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 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,18 +289,16 @@ 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()

Expand All @@ -317,6 +308,20 @@ class ContainerView: RCTView {
}
}

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 3a283dd

Please sign in to comment.