Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
freak4pc committed May 28, 2024
1 parent beb5e98 commit 496ebef
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Example/Example/LottieViewLayoutDemoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct LottieViewLayoutDemoView: View {
HStack {
VStack {
LottieView(animation: .named("Samples/LottieLogo1"))
.configure(\.contentMode, value: .scaleAspectFit)
.configure(\.contentMode, to: .scaleAspectFit)
.looping()
.frame(maxWidth: 100)

Expand Down
27 changes: 25 additions & 2 deletions Sources/Public/Animation/LottieView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,39 @@ public struct LottieView<Placeholder: View>: UIViewConfiguringSwiftUIView {
/// Returns a copy of this `LottieView` updated to have the specific configuration property
/// applied to its represented `LottieAnimationView` whenever it is updated via the `updateUIView(...)`
/// or `updateNSView(...)` methods.
///
/// - note: This configuration will be applied on every SwiftUI render pass.
/// Be wary of applying heavy side-effects as configuration values.
public func configure<Property>(
_ property: ReferenceWritableKeyPath<LottieAnimationView, Property>,
value: Property
) -> Self {
to value: Property)
-> Self
{
configure { $0[keyPath: property] = value }
}

/// Returns a copy of this `LottieView` updated to have the specific configuration property
/// applied to its represented `LottieAnimationView` whenever it is updated via the `updateUIView(...)`
/// or `updateNSView(...)` methods.
///
/// - note: If the `value` is already the currently-applied configuration value, it won't be applied
public func configure<Property: Equatable>(
_ property: ReferenceWritableKeyPath<LottieAnimationView, Property>,
to value: Property)
-> Self
{
configure {
guard $0[keyPath: property] != value else { return }
$0[keyPath: property] = value
}
}

/// Returns a copy of this `LottieView` updated to have the given closure applied to its
/// represented `LottieAnimationView` whenever it is updated via the `updateUIView(…)`
/// or `updateNSView(…)` method.
///
/// - note: This configuration closure will be executed on every SwiftUI render pass.
/// Be wary of applying heavy side-effects inside it.
public func configure(_ configure: @escaping (LottieAnimationView) -> Void) -> Self {
var copy = self
copy.configurations.append { context in
Expand Down

0 comments on commit 496ebef

Please sign in to comment.