Skip to content

Commit

Permalink
Add LottieAnimationView.maskAnimationToBounds configuration (#2008)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnny-duo authored Mar 28, 2023
1 parent 9c2d64e commit cc7b5c6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Sources/Private/CoreAnimation/CoreAnimationLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ final class CoreAnimationLayer: BaseAnimationLayer {
imageProvider: AnimationImageProvider,
textProvider: AnimationTextProvider,
fontProvider: AnimationFontProvider,
maskAnimationToBounds: Bool,
compatibilityTrackerMode: CompatibilityTracker.Mode,
logger: LottieLogger)
throws
Expand All @@ -31,7 +32,7 @@ final class CoreAnimationLayer: BaseAnimationLayer {
compatibilityTracker = CompatibilityTracker(mode: compatibilityTrackerMode, logger: logger)
valueProviderStore = ValueProviderStore(logger: logger)
super.init()
masksToBounds = true
masksToBounds = maskAnimationToBounds
setup()
try setupChildLayers()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ final class MainThreadAnimationLayer: CALayer, RootAnimationLayer {
imageProvider: AnimationImageProvider,
textProvider: AnimationTextProvider,
fontProvider: AnimationFontProvider,
maskAnimationToBounds: Bool,
logger: LottieLogger)
{
layerImageProvider = LayerImageProvider(imageProvider: imageProvider, assets: animation.assetLibrary?.imageAssets)
Expand All @@ -31,7 +32,7 @@ final class MainThreadAnimationLayer: CALayer, RootAnimationLayer {
animationLayers = []
self.logger = logger
super.init()
masksToBounds = true
masksToBounds = maskAnimationToBounds
bounds = animation.bounds
let layers = animation.layers.initializeCompositionLayers(
assetLibrary: animation.assetLibrary,
Expand Down
10 changes: 10 additions & 0 deletions Sources/Public/Animation/LottieAnimationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,13 @@ open class LottieAnimationView: LottieAnimationViewBase {
}
}

/// Whether or not the animation is masked to the bounds. Defaults to true.
public var maskAnimationToBounds = true {
didSet {
animationLayer?.masksToBounds = maskAnimationToBounds
}
}

/// Returns `true` if the animation is currently playing.
public var isAnimationPlaying: Bool {
guard let animationLayer = animationLayer else {
Expand Down Expand Up @@ -1134,6 +1141,7 @@ open class LottieAnimationView: LottieAnimationViewBase {
imageProvider: imageProvider.cachedImageProvider,
textProvider: textProvider,
fontProvider: fontProvider,
maskAnimationToBounds: maskAnimationToBounds,
logger: logger)
}

Expand All @@ -1144,6 +1152,7 @@ open class LottieAnimationView: LottieAnimationViewBase {
imageProvider: imageProvider.cachedImageProvider,
textProvider: textProvider,
fontProvider: fontProvider,
maskAnimationToBounds: maskAnimationToBounds,
compatibilityTrackerMode: .track,
logger: logger)

Expand Down Expand Up @@ -1179,6 +1188,7 @@ open class LottieAnimationView: LottieAnimationViewBase {
imageProvider: imageProvider.cachedImageProvider,
textProvider: textProvider,
fontProvider: fontProvider,
maskAnimationToBounds: maskAnimationToBounds,
compatibilityTrackerMode: .abort,
logger: logger)

Expand Down
1 change: 1 addition & 0 deletions Tests/AutomaticEngineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ final class AutomaticEngineTests: XCTestCase {
imageProvider: BundleImageProvider(bundle: Bundle.main, searchPath: nil),
textProvider: DefaultTextProvider(),
fontProvider: DefaultFontProvider(),
maskAnimationToBounds: true,
compatibilityTrackerMode: .track,
logger: .shared))

Expand Down

0 comments on commit cc7b5c6

Please sign in to comment.