diff --git a/packages/core/ios/LottieReactNative/ContainerView.swift b/packages/core/ios/LottieReactNative/ContainerView.swift index 766d6c9e..d60b6289 100644 --- a/packages/core/ios/LottieReactNative/ContainerView.swift +++ b/packages/core/ios/LottieReactNative/ContainerView.swift @@ -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]) { @@ -296,11 +289,8 @@ 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 @@ -308,6 +298,7 @@ class ContainerView: RCTView { addSubview(next) + applyContentMode() applyColorProperties() playIfNeeded() @@ -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 }