Skip to content
Permalink
Browse files

Merge pull request #25 from ParkGwangBeom/master

trailing closure
  • Loading branch information...
gre4ixin committed Mar 3, 2019
2 parents d0bd22a + d2ee70f commit de9a8be68a4b315d0b07a55495e20528d03fbe6b
@@ -42,7 +42,7 @@ extension AnimatedSink where Base: UIView {
return AnimatedSink<Base>(base: self.base, type: type)
}

public func animation(duration: TimeInterval, options: UIView.AnimationOptions = [], animations: @escaping ()->Void) -> AnimatedSink<Base> {
public func animation(duration: TimeInterval, options: UIView.AnimationOptions = [], animations: @escaping () -> Void) -> AnimatedSink<Base> {
let type = AnimationType<Base>(type: RxAnimationType.animation, duration: duration, animations: { _ in animations() })
return AnimatedSink<Base>(base: self.base, type: type)
}
@@ -14,19 +14,19 @@ extension Reactive where Base: UIView {
extension AnimatedSink where Base: UIView {
public var isHidden: Binder<Bool> {
return Binder(self.base) { view, hidden in
self.type.animate(view: view, binding: {
self.type.animate(view: view) {
view.isHidden = hidden
})
}
}
}
}

extension AnimatedSink where Base: UIView {
public var alpha: Binder<CGFloat> {
return Binder(self.base) { view, alpha in
self.type.animate(view: view, binding: {
self.type.animate(view: view) {
view.alpha = alpha
})
}
}
}
}
@@ -35,18 +35,18 @@ extension AnimatedSink where Base: UIView {
extension AnimatedSink where Base: UILabel {
public var text: Binder<String> {
return Binder(self.base) { label, text in
self.type.animate(view: label, binding: {
self.type.animate(view: label) {
guard let label = label as? UILabel else { return }
label.text = text
})
}
}
}
public var attributedText: Binder<NSAttributedString> {
return Binder(self.base) { label, text in
self.type.animate(view: label, binding: {
self.type.animate(view: label) {
guard let label = label as? UILabel else { return }
label.attributedText = text
})
}
}
}
}
@@ -55,18 +55,18 @@ extension AnimatedSink where Base: UILabel {
extension AnimatedSink where Base: UIControl {
public var isEnabled: Binder<Bool> {
return Binder(self.base) { control, enabled in
self.type.animate(view: control, binding: {
self.type.animate(view: control) {
guard let control = control as? UIControl else { return }
control.isEnabled = enabled
})
}
}
}
public var isSelected: Binder<Bool> {
return Binder(self.base) { control, selected in
self.type.animate(view: control, binding: {
self.type.animate(view: control) {
guard let control = control as? UIControl else { return }
control.isSelected = selected
})
}
}
}
}
@@ -75,26 +75,26 @@ extension AnimatedSink where Base: UIControl {
extension AnimatedSink where Base: UIButton {
public var title: Binder<String> {
return Binder(self.base) { button, title in
self.type.animate(view: button, binding: {
self.type.animate(view: button) {
guard let button = button as? UIButton else { return }
button.setTitle(title, for: button.state)
})
}
}
}
public var image: Binder<UIImage?> {
return Binder(self.base) { button, image in
self.type.animate(view: button, binding: {
self.type.animate(view: button) {
guard let button = button as? UIButton else { return }
button.setImage(image, for: button.state)
})
}
}
}
public var backgroundImage: Binder<UIImage?> {
return Binder(self.base) { button, image in
self.type.animate(view: button, binding: {
self.type.animate(view: button) {
guard let button = button as? UIButton else { return }
button.setBackgroundImage(image, for: button.state)
})
}
}
}
}
@@ -103,10 +103,10 @@ extension AnimatedSink where Base: UIButton {
extension AnimatedSink where Base: UIImageView {
public var image: Binder<UIImage?> {
return Binder(self.base) { imageView, image in
self.type.animate(view: imageView, binding: {
self.type.animate(view: imageView) {
guard let imageView = imageView as? UIImageView else { return }
imageView.image = image
})
}
}
}
}
@@ -126,19 +126,19 @@ extension AnimatedSink where Base: NSLayoutConstraint {
guard let view = constraint.firstItem as? UIView,
let superview = view.superview else { return }

self.type.animate(view: superview, binding: {
self.type.animate(view: superview) {
constraint.constant = constant
})
}
}
}
public var isActive: Binder<Bool> {
return Binder(self.base) { constraint, active in
guard let view = constraint.firstItem as? UIView,
let superview = view.superview else { return }

self.type.animate(view: superview, binding: {
self.type.animate(view: superview) {
constraint.isActive = active
})
}
}
}
}
@@ -31,9 +31,9 @@ public struct AnimationType<Base> {
let duration: TimeInterval
let options: UIView.AnimationOptions

let setup: ((UIView)->Void)?
let animations: ((UIView)->Void)?
let completion: ((Bool)->Void)?
let setup: ((UIView) -> Void)?
let animations: ((UIView) -> Void)?
let completion: ((Bool) -> Void)?

/**
* creates an animation "future"
@@ -44,7 +44,7 @@ public struct AnimationType<Base> {
* - parameter animations: block of code to be executed during animation
* - parameter completion: block of code to be executed after the animation has finished
*/
public init(type: RxAnimationType, duration: TimeInterval, options: UIView.AnimationOptions = [], setup: ((UIView)->Void)? = nil, animations: ((UIView)->Void)?, completion: ((Bool)->Void)? = nil) {
public init(type: RxAnimationType, duration: TimeInterval, options: UIView.AnimationOptions = [], setup: ((UIView)->Void)? = nil, animations: ((UIView) -> Void)?, completion: ((Bool) -> Void)? = nil) {
self.type = type
self.duration = duration
self.options = options
@@ -58,7 +58,7 @@ public struct AnimationType<Base> {
* - parameter view: a view to run the animations on
* - parameter block: a custom block to inject inside the animation
*/
public func animate(view: UIView, binding: (()->Void)?) {
public func animate(view: UIView, binding: (() -> Void)?) {
setup?(view)

DispatchQueue.main.async {

0 comments on commit de9a8be

Please sign in to comment.
You can’t perform that action at this time.