You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

5 years ago
  1. //
  2. // UIViewPropertyAnimator+Rx.swift
  3. // RxSwiftExt
  4. //
  5. // Created by Wittemberg, Thibault on 29/03/18.
  6. // Copyright © 2017 RxSwift Community. All rights reserved.
  7. //
  8. #if os(iOS)
  9. import Foundation
  10. import UIKit
  11. import RxSwift
  12. import RxCocoa
  13. @available(iOS 10.0, *)
  14. public extension Reactive where Base: UIViewPropertyAnimator {
  15. /**
  16. Bindable extension for `fractionComplete` property.
  17. */
  18. public var fractionComplete: Binder<CGFloat> {
  19. return Binder(base) { propertyAnimator, fractionComplete in
  20. propertyAnimator.fractionComplete = fractionComplete
  21. }
  22. }
  23. /// Provides a Completable that triggers the UIViewPropertyAnimator upon subscription
  24. /// and completes once the animation ends.
  25. ///
  26. /// - Parameter afterDelay: the delay to apply to the animation start
  27. ///
  28. /// - Returns: Completable
  29. func animate(afterDelay delay: TimeInterval = 0) -> Completable {
  30. return Completable.create { [base] completable in
  31. base.addCompletion { position in
  32. guard position == .end else { return }
  33. completable(.completed)
  34. }
  35. if delay != 0 {
  36. base.startAnimation(afterDelay: delay)
  37. } else {
  38. base.startAnimation()
  39. }
  40. return Disposables.create {
  41. base.stopAnimation(true)
  42. }
  43. }
  44. }
  45. }
  46. #endif