Skip to content

Commit

Permalink
Code review from kb
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleve committed Mar 10, 2021
1 parent dc2c88c commit 5aa80f6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
15 changes: 10 additions & 5 deletions ListableUI/Sources/Item/ItemContentCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ public final class ItemContentCoordinatorActions<Content:ItemContent>
/// Allows you to update the displayed item via the provided closure, with an optional
/// animation or delay.
///
/// Note that the `update` callback is invoked after the provided `delay`, and
/// is passed the value of the `Item` at that point in time.
///
/// ```
/// func wasSelected() {
/// self.update(animation: .animated(0.15), after: 1.0) { item in
Expand All @@ -160,17 +163,19 @@ public final class ItemContentCoordinatorActions<Content:ItemContent>
public func update(
animation: ViewAnimation = .default,
after delay: TimeInterval = 0,
update : (inout Item<Content>) -> ()
update : @escaping (inout Item<Content>) -> ()
) {
var new = self.currentProvider()

update(&new)

if delay > 0 {
Timer.scheduledTimer(withTimeInterval: delay, repeats: false) { _ in
var new = self.currentProvider()
update(&new)

self.updateCallback(new, animation)
}
} else {
var new = self.currentProvider()
update(&new)

self.updateCallback(new, animation)
}
}
Expand Down
8 changes: 4 additions & 4 deletions ListableUI/Sources/ViewAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public enum ViewAnimation {
case animated(TimeInterval = 0.25, options : Set<AnimationOptions> = .default)

/// A spring based animation is performed.
/// The default parameters are 0.25 seconds and `UISpringTimingParameters()` timing.
case spring(TimeInterval = 0.25, timing : UISpringTimingParameters = .init())
/// The default value is `UISpringTimingParameters()`.
case spring(UISpringTimingParameters = .init())

/// Ands the animation with the provided bool, returning the animation if true, and `.none` if false.
public func and(with animated : Bool) -> ViewAnimation {
Expand Down Expand Up @@ -58,8 +58,8 @@ public enum ViewAnimation {
}
)

case .spring(let duration, let timing):
let animator = UIViewPropertyAnimator(duration: duration, timingParameters: timing)
case .spring(let timing):
let animator = UIViewPropertyAnimator(duration: 0, timingParameters: timing)

animator.addAnimations(animations)

Expand Down
6 changes: 5 additions & 1 deletion ListableUI/Tests/Item/ItemContentCoordinatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ class ItemContentCoordinatorActionsTests : XCTestCase
$0.content.value = "update2"
}

XCTAssertEqual(item.content.value, "update2")
actions.update {
$0.content.value = "update3"
}

XCTAssertEqual(item.content.value, "update3")
XCTAssertEqual(callbackCount, 2)
}
}
Expand Down

0 comments on commit 5aa80f6

Please sign in to comment.