Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animated assign subscriber #17

Merged
merged 8 commits into from
Jun 25, 2020
Merged

Animated assign subscriber #17

merged 8 commits into from
Jun 25, 2020

Conversation

icanzilb
Copy link
Contributor

@icanzilb icanzilb commented May 3, 2020

This PR adds a variation of assign(to:on:) with an extra parameter allowing the user to set an animation transition to play when emitting output values.

E.g. if you have:

let counts = ["One", "Two", "Three", "Four", "Five"]

Timer.publish(every: 1, on: RunLoop.main, in: .common)
    .autoconnect()
    .scan(0) { (result, _) -> Int in
        return result + 1 >= counts.count ? 0 : result + 1
    }
    .map { counts[$0] }
    .assign(to: \UILabel.text, on: label, animation: .flip(direction: .left, duration: 0.25))
    .store(in: &subscriptions)

It makes the updates to the label animated like so:

countdown

@icanzilb icanzilb requested a review from freak4pc May 3, 2020 18:38
Copy link
Member

@freak4pc freak4pc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Have a few quick notes here :)

Sources/AnimatedAssignSubscriber.swift Outdated Show resolved Hide resolved
Sources/AnimatedAssignSubscriber.swift Outdated Show resolved Hide resolved
Sources/AnimatedAssignSubscriber.swift Outdated Show resolved Hide resolved
Sources/AnimatedAssignSubscriber.swift Outdated Show resolved Hide resolved
Sources/AnimatedAssignSubscriber.swift Outdated Show resolved Hide resolved
icanzilb and others added 6 commits May 4, 2020 12:27
Co-authored-by: Shai Mishali <freak4pc@gmail.com>
Co-authored-by: Shai Mishali <freak4pc@gmail.com>
Co-authored-by: Shai Mishali <freak4pc@gmail.com>
Co-authored-by: Shai Mishali <freak4pc@gmail.com>
Co-authored-by: Shai Mishali <freak4pc@gmail.com>
@icanzilb
Copy link
Contributor Author

icanzilb commented May 4, 2020

Thanks @freak4pc - merged and removed the guard too.

@icanzilb icanzilb requested a review from freak4pc May 4, 2020 10:35
Copy link
Member

@freak4pc freak4pc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay here, crazy few days. Noticed two more quick notes that I wanted to ask you about.

Comment on lines 50 to 51
/// ```
public func assign<Root: UIView>(to keyPath: ReferenceWritableKeyPath<Root, Self.Output>, on object: Root, animation: AssignTransition) -> AnyCancellable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this looks misaligned... tabs and spaces together?
image

Comment on lines 74 to 79
object[keyPath: keyPath] = value
animations()
},
completion: completion)
})
.assign(to: keyPath, on: object)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another question that popped to my head,
You're already setting the value inside the animation block, and the assign will do so again.

Maybe it's worth swapping the assign with something like sink(receiveValue: { _ in }). Just to active the chain? (same for below)

@freak4pc
Copy link
Member

Hey @icanzilb - any chance you have a moment to answer above questions? Happy to help carry this over the merge line with you

@icanzilb
Copy link
Contributor Author

@freak4pc yikes, it seems I missed this one - looking at it this afternoon 👍🏼

@icanzilb icanzilb changed the title [WIP] Animated assign subscriber Animated assign subscriber May 18, 2020
@icanzilb icanzilb requested a review from freak4pc May 18, 2020 11:24
@icanzilb
Copy link
Contributor Author

@freak4pc 👆🏼

Copy link
Member

@freak4pc freak4pc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes, was sure I already merged this.
Sorry @icanzilb ! Looks good.

@freak4pc freak4pc merged commit b1e5b22 into master Jun 25, 2020
@freak4pc freak4pc deleted the marin_todorov/assign-animate branch June 25, 2020 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants