Skip to content

Commit

Permalink
Add convenient .allowsUserInteraction modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
PimCoumans committed Apr 16, 2024
1 parent a34558d commit f6c6523
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Sources/AnimationPlanner/Protocols/AnimationModifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public protocol AnimationModifiers: Animation {
/// - Note: Using `.repeats` will break expected behavior when used in a sequence
func options(_ options: UIView.AnimationOptions) -> Self

/// Enables interaction on your parent views while this animation is running
func allowUserInteraction() -> Self

/// Sets a `CAMediaTimingFunction` for the animation. Overwrites possible previously set functions.
///
/// Overrides any animation curves previously set with ``timingFunction(_:)``
Expand All @@ -36,6 +39,9 @@ extension Animate: AnimationModifiers {
// Update options by creating a union of existing options
mutate { $0.options = $0.options?.union(options) ?? options }
}
public func allowUserInteraction() -> Animate {
mutate { $0.options = ($0.options ?? []).union(.allowUserInteraction) }
}
public func timingFunction(_ function: CAMediaTimingFunction) -> Self {
mutate { $0.timingFunction = function}
}
Expand Down Expand Up @@ -127,6 +133,9 @@ extension AnimateSpring: AnimationModifiers where Contained: AnimationModifiers
public func options(_ options: UIView.AnimationOptions) -> Self {
mutate { $0.animation = animation.options(options) }
}
public func allowUserInteraction() -> AnimateSpring<Springed> {
mutate { $0.animation = animation.allowUserInteraction() }
}
public func timingFunction(_ function: CAMediaTimingFunction) -> Self {
mutate { $0.animation = animation.timingFunction(function) }
}
Expand All @@ -140,6 +149,9 @@ extension AnimateDelayed: AnimationModifiers where Contained: Animation & Animat
public func options(_ options: UIView.AnimationOptions) -> Self {
mutate { $0.animation = animation.options(options) }
}
public func allowUserInteraction() -> AnimateDelayed<Delayed> {
mutate { $0.animation = animation.allowUserInteraction() }
}
public func timingFunction(_ function: CAMediaTimingFunction) -> Self {
mutate { $0.animation = animation.timingFunction(function) }
}
Expand Down
4 changes: 4 additions & 0 deletions Tests/AnimationPlannerTests/BuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class BuilderTests: AnimationPlannerTests {
let simplerSpring = AnimateSpring(duration: 1, dampingRatio: 2)
XCTAssertEqual(spring.dampingRatio, simplerSpring.dampingRatio)
XCTAssertEqual(spring.duration, simplerSpring.duration)
let springOptions = spring.options ?? []
XCTAssertFalse(springOptions.contains(.allowUserInteraction))
let editedOptions = spring.allowUserInteraction().options ?? []
XCTAssertTrue(editedOptions.contains(.allowUserInteraction))

let delay = spring.delayed(3)
XCTAssertEqual(delay.duration, spring.duration + delay.delay)
Expand Down

0 comments on commit f6c6523

Please sign in to comment.