Last active
October 13, 2018 18:46
-
-
Save snowtema/e40576b7a464d04463dfda386642355e to your computer and use it in GitHub Desktop.
UIProgressView animation with RxAnimated
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import RxAnimated | |
import RxSwift | |
import RxCocoa | |
extension AnimatedSink where Base: UIProgressView { | |
public var progress: Binder<Float> { | |
let animation = self.type! | |
return Binder(self.base) { (progressView: UIProgressView, progress: Float) in | |
animation.animate(view: progressView) { | |
guard let progressView = progressView as? UIProgressView else { return } | |
progressView.progress = progress | |
} | |
} | |
} | |
public func layout(duration: TimeInterval) -> AnimatedSink<Base> { | |
let type = AnimationType<Base>(type: RxAnimationType.animation, duration: duration, animations: { view in | |
view.layoutIfNeeded() | |
}) | |
return AnimatedSink<Base>(base: self.base, type: type) | |
} | |
} | |
// Use: | |
// ------------ | |
// progressSubject.asObservable() | |
// .observeOn(MainScheduler.instance) | |
// .bind(animated: progressView.rx.animated.layout(duration: 0.33).progress) | |
// .disposed(by: bag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment