Skip to content

Instantly share code, notes, and snippets.

@snowtema
Last active October 13, 2018 18:46
Show Gist options
  • Save snowtema/e40576b7a464d04463dfda386642355e to your computer and use it in GitHub Desktop.
Save snowtema/e40576b7a464d04463dfda386642355e to your computer and use it in GitHub Desktop.
UIProgressView animation with RxAnimated
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