mirror of
https://github.com/ReactiveX/RxSwift.git
synced 2024-10-05 06:27:29 +03:00
Replaces AnyObserver
with UIBindingObserver
in public interface.
This commit is contained in:
parent
dc933008a8
commit
832f79cd02
@ -25,20 +25,20 @@ extension Reactive where Base: NSLayoutConstraint {
|
||||
/**
|
||||
Bindable sink for `constant` property.
|
||||
*/
|
||||
public var constant: AnyObserver<CGFloat> {
|
||||
public var constant: UIBindingObserver<Base, CGFloat> {
|
||||
return UIBindingObserver(UIElement: self.base) { constraint, constant in
|
||||
constraint.constant = constant
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Bindable sink for `active` property.
|
||||
*/
|
||||
@available(iOS 8, OSX 10.10, *)
|
||||
public var active: AnyObserver<Bool> {
|
||||
public var active: UIBindingObserver<Base, Bool> {
|
||||
return UIBindingObserver(UIElement: self.base) { constraint, value in
|
||||
constraint.isActive = value
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,10 +81,10 @@ extension Reactive where Base: NSControl {
|
||||
/**
|
||||
Bindable sink for `enabled` property.
|
||||
*/
|
||||
public var enabled: AnyObserver<Bool> {
|
||||
public var enabled: UIBindingObserver<Base, Bool> {
|
||||
return UIBindingObserver(UIElement: self.base) { (owner, value) in
|
||||
owner.isEnabled = value
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ extension Reactive where Base: NSImageView {
|
||||
/**
|
||||
Bindable sink for `image` property.
|
||||
*/
|
||||
public var image: AnyObserver<NSImage?> {
|
||||
public var image: UIBindingObserver<Base, NSImage?> {
|
||||
return image(transitionType: nil)
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ extension Reactive where Base: NSImageView {
|
||||
- parameter transitionType: Optional transition type while setting the image (kCATransitionFade, kCATransitionMoveIn, ...)
|
||||
*/
|
||||
@available(*, deprecated, renamed: "image(transitionType:)")
|
||||
public func imageAnimated(_ transitionType: String?) -> AnyObserver<NSImage?> {
|
||||
public func imageAnimated(_ transitionType: String?) -> UIBindingObserver<Base, NSImage?> {
|
||||
return UIBindingObserver(UIElement: self.base) { control, value in
|
||||
if let transitionType = transitionType {
|
||||
if value != nil {
|
||||
@ -44,7 +44,7 @@ extension Reactive where Base: NSImageView {
|
||||
control.layer?.removeAllAnimations()
|
||||
}
|
||||
control.image = value
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,7 +52,7 @@ extension Reactive where Base: NSImageView {
|
||||
|
||||
- parameter transitionType: Optional transition type while setting the image (kCATransitionFade, kCATransitionMoveIn, ...)
|
||||
*/
|
||||
public func image(transitionType: String? = nil) -> AnyObserver<NSImage?> {
|
||||
public func image(transitionType: String? = nil) -> UIBindingObserver<Base, NSImage?> {
|
||||
return UIBindingObserver(UIElement: self.base) { control, value in
|
||||
if let transitionType = transitionType {
|
||||
if value != nil {
|
||||
@ -67,7 +67,7 @@ extension Reactive where Base: NSImageView {
|
||||
control.layer?.removeAllAnimations()
|
||||
}
|
||||
control.image = value
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,19 +18,19 @@
|
||||
/**
|
||||
Bindable sink for `hidden` property.
|
||||
*/
|
||||
public var hidden: AnyObserver<Bool> {
|
||||
public var hidden: UIBindingObserver<Base, Bool> {
|
||||
return UIBindingObserver(UIElement: self.base) { view, value in
|
||||
view.isHidden = value
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Bindable sink for `alphaValue` property.
|
||||
*/
|
||||
public var alpha: AnyObserver<CGFloat> {
|
||||
public var alpha: UIBindingObserver<Base, CGFloat> {
|
||||
return UIBindingObserver(UIElement: self.base) { view, value in
|
||||
view.alphaValue = value
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,14 +18,14 @@ extension Reactive where Base: UIActivityIndicatorView {
|
||||
/**
|
||||
Bindable sink for `startAnimating()`, `stopAnimating()` methods.
|
||||
*/
|
||||
public var animating: AnyObserver<Bool> {
|
||||
public var animating: UIBindingObserver<Base, Bool> {
|
||||
return UIBindingObserver(UIElement: self.base) { activityIndicator, active in
|
||||
if active {
|
||||
activityIndicator.startAnimating()
|
||||
} else {
|
||||
activityIndicator.stopAnimating()
|
||||
}
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,10 +22,10 @@ extension Reactive where Base: UIAlertAction {
|
||||
/**
|
||||
Bindable sink for `enabled` property.
|
||||
*/
|
||||
public var enabled: AnyObserver<Bool> {
|
||||
public var enabled: UIBindingObserver<Base, Bool> {
|
||||
return UIBindingObserver(UIElement: self.base) { alertAction, value in
|
||||
alertAction.isEnabled = value
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,10 +20,10 @@ import Foundation
|
||||
/**
|
||||
Bindable sink for `networkActivityIndicatorVisible`.
|
||||
*/
|
||||
public var networkActivityIndicatorVisible: AnyObserver<Bool> {
|
||||
public var networkActivityIndicatorVisible: UIBindingObserver<Base, Bool> {
|
||||
return UIBindingObserver(UIElement: self.base) { application, active in
|
||||
application.isNetworkActivityIndicatorVisible = active
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -20,10 +20,10 @@ extension Reactive where Base: UIBarButtonItem {
|
||||
/**
|
||||
Bindable sink for `enabled` property.
|
||||
*/
|
||||
public var enabled: AnyObserver<Bool> {
|
||||
public var enabled: UIBindingObserver<Base, Bool> {
|
||||
return UIBindingObserver(UIElement: self.base) { UIElement, value in
|
||||
UIElement.isEnabled = value
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,10 +59,10 @@ extension Reactive where Base: UIButton {
|
||||
/**
|
||||
Reactive wrapper for `setTitle(_:controlState:)`
|
||||
*/
|
||||
public func title(controlState: UIControlState = []) -> AnyObserver<String?> {
|
||||
return UIBindingObserver<UIButton, String?>(UIElement: self.base) { (button, title) -> () in
|
||||
public func title(controlState: UIControlState = []) -> UIBindingObserver<Base, String?> {
|
||||
return UIBindingObserver<Base, String?>(UIElement: self.base) { (button, title) -> () in
|
||||
button.setTitle(title, for: controlState)
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -19,19 +19,19 @@ extension Reactive where Base: UIControl {
|
||||
/**
|
||||
Bindable sink for `enabled` property.
|
||||
*/
|
||||
public var enabled: AnyObserver<Bool> {
|
||||
public var enabled: UIBindingObserver<Base, Bool> {
|
||||
return UIBindingObserver(UIElement: self.base) { control, value in
|
||||
control.isEnabled = value
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Bindable sink for `selected` property.
|
||||
*/
|
||||
public var selected: AnyObserver<Bool> {
|
||||
public var selected: UIBindingObserver<Base, Bool> {
|
||||
return UIBindingObserver(UIElement: self.base) { control, selected in
|
||||
control.isSelected = selected
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,7 +19,7 @@ extension Reactive where Base: UIImageView {
|
||||
/**
|
||||
Bindable sink for `image` property.
|
||||
*/
|
||||
public var image: AnyObserver<UIImage?> {
|
||||
public var image: UIBindingObserver<Base, UIImage?> {
|
||||
return image(transitionType: nil)
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ extension Reactive where Base: UIImageView {
|
||||
- parameter transitionType: Optional transition type while setting the image (kCATransitionFade, kCATransitionMoveIn, ...)
|
||||
*/
|
||||
@available(*, deprecated, renamed: "image(transitionType:)")
|
||||
public func imageAnimated(_ transitionType: String?) -> AnyObserver<UIImage?> {
|
||||
public func imageAnimated(_ transitionType: String?) -> UIBindingObserver<Base, UIImage?> {
|
||||
return UIBindingObserver(UIElement: base) { imageView, image in
|
||||
if let transitionType = transitionType {
|
||||
if image != nil {
|
||||
@ -44,7 +44,7 @@ extension Reactive where Base: UIImageView {
|
||||
imageView.layer.removeAllAnimations()
|
||||
}
|
||||
imageView.image = image
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -52,7 +52,7 @@ extension Reactive where Base: UIImageView {
|
||||
|
||||
- parameter transitionType: Optional transition type while setting the image (kCATransitionFade, kCATransitionMoveIn, ...)
|
||||
*/
|
||||
public func image(transitionType: String? = nil) -> AnyObserver<UIImage?> {
|
||||
public func image(transitionType: String? = nil) -> UIBindingObserver<Base, UIImage?> {
|
||||
return UIBindingObserver(UIElement: base) { imageView, image in
|
||||
if let transitionType = transitionType {
|
||||
if image != nil {
|
||||
@ -67,7 +67,7 @@ extension Reactive where Base: UIImageView {
|
||||
imageView.layer.removeAllAnimations()
|
||||
}
|
||||
imageView.image = image
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,19 +19,19 @@ extension Reactive where Base: UILabel {
|
||||
/**
|
||||
Bindable sink for `text` property.
|
||||
*/
|
||||
public var text: AnyObserver<String?> {
|
||||
public var text: UIBindingObserver<Base, String?> {
|
||||
return UIBindingObserver(UIElement: self.base) { label, text in
|
||||
label.text = text
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Bindable sink for `attributedText` property.
|
||||
*/
|
||||
public var attributedText: AnyObserver<NSAttributedString?> {
|
||||
public var attributedText: UIBindingObserver<Base, NSAttributedString?> {
|
||||
return UIBindingObserver(UIElement: self.base) { label, text in
|
||||
label.attributedText = text
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,10 +18,10 @@ extension Reactive where Base: UINavigationItem {
|
||||
/**
|
||||
Bindable sink for `title` property.
|
||||
*/
|
||||
public var title: AnyObserver<String?> {
|
||||
public var title: UIBindingObserver<Base, String?> {
|
||||
return UIBindingObserver(UIElement: self.base) { navigationItem, text in
|
||||
navigationItem.title = text
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,10 +19,10 @@ extension Reactive where Base: UIPageControl {
|
||||
/**
|
||||
Bindable sink for `currentPage` property.
|
||||
*/
|
||||
public var currentPage: AnyObserver<Int> {
|
||||
public var currentPage: UIBindingObserver<Base, Int> {
|
||||
return UIBindingObserver(UIElement: self.base) { controller, page in
|
||||
controller.currentPage = page
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,10 +19,10 @@ extension Reactive where Base: UIProgressView {
|
||||
/**
|
||||
Bindable sink for `progress` property
|
||||
*/
|
||||
public var progress: AnyObserver<Float> {
|
||||
public var progress: UIBindingObserver<Base, Float> {
|
||||
return UIBindingObserver(UIElement: self.base) { progressView, progress in
|
||||
progressView.progress = progress
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,14 +18,14 @@ extension Reactive where Base: UIRefreshControl {
|
||||
/**
|
||||
Bindable sink for `beginRefreshing()`, `endRefreshing()` methods.
|
||||
*/
|
||||
public var refreshing: AnyObserver<Bool> {
|
||||
public var refreshing: UIBindingObserver<Base, Bool> {
|
||||
return UIBindingObserver(UIElement: self.base) { refreshControl, refresh in
|
||||
if refresh {
|
||||
refreshControl.beginRefreshing()
|
||||
} else {
|
||||
refreshControl.endRefreshing()
|
||||
}
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -54,10 +54,10 @@ extension Reactive where Base: UIScrollView {
|
||||
/**
|
||||
Bindable sink for `scrollEnabled` property.
|
||||
*/
|
||||
public var scrollEnabled: AnyObserver<Bool> {
|
||||
public var scrollEnabled: UIBindingObserver<Base, Bool> {
|
||||
return UIBindingObserver(UIElement: self.base) { scrollView, scrollEnabled in
|
||||
scrollView.isScrollEnabled = scrollEnabled
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,10 +19,10 @@ extension Reactive where Base: UITabBarItem {
|
||||
/**
|
||||
Bindable sink for `badgeValue` property.
|
||||
*/
|
||||
public var badgeValue: AnyObserver<String?> {
|
||||
public var badgeValue: UIBindingObserver<Base, String?> {
|
||||
return UIBindingObserver(UIElement: self.base) { tabBarItem, badgeValue in
|
||||
tabBarItem.badgeValue = badgeValue
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,19 +18,19 @@ extension Reactive where Base: UIView {
|
||||
/**
|
||||
Bindable sink for `hidden` property.
|
||||
*/
|
||||
public var hidden: AnyObserver<Bool> {
|
||||
public var hidden: UIBindingObserver<Base, Bool> {
|
||||
return UIBindingObserver(UIElement: self.base) { view, hidden in
|
||||
view.isHidden = hidden
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Bindable sink for `alpha` property.
|
||||
*/
|
||||
public var alpha: AnyObserver<CGFloat> {
|
||||
public var alpha: UIBindingObserver<Base, CGFloat> {
|
||||
return UIBindingObserver(UIElement: self.base) { view, alpha in
|
||||
view.alpha = alpha
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,10 +20,10 @@ import Foundation
|
||||
/**
|
||||
Bindable sink for `title`.
|
||||
*/
|
||||
public var title: AnyObserver<String> {
|
||||
public var title: UIBindingObserver<Base, String> {
|
||||
return UIBindingObserver(UIElement: self.base) { viewController, title in
|
||||
viewController.title = title
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -14,15 +14,15 @@ import CoreLocation
|
||||
#endif
|
||||
|
||||
private extension Reactive where Base: UILabel {
|
||||
var driveCoordinates: AnyObserver<CLLocationCoordinate2D> {
|
||||
var driveCoordinates: UIBindingObserver<Base, CLLocationCoordinate2D> {
|
||||
return UIBindingObserver(UIElement: base) { label, location in
|
||||
label.text = "Lat: \(location.latitude)\nLon: \(location.longitude)"
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension Reactive where Base: UIView {
|
||||
var driveAuthorization: AnyObserver<Bool> {
|
||||
var driveAuthorization: UIBindingObserver<Base, Bool> {
|
||||
return UIBindingObserver(UIElement: base) { view, authorized in
|
||||
if authorized {
|
||||
view.isHidden = true
|
||||
@ -32,7 +32,7 @@ private extension Reactive where Base: UIView {
|
||||
view.isHidden = false
|
||||
view.superview?.bringSubview(toFront:view)
|
||||
}
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ struct Colors {
|
||||
}
|
||||
|
||||
extension Reactive where Base: UINavigationController {
|
||||
var serviceState: AnyObserver<ServiceState?> {
|
||||
var serviceState: UIBindingObserver<Base, ServiceState?> {
|
||||
return UIBindingObserver(UIElement: base) { navigationController, maybeServiceState in
|
||||
// if nil is being bound, then don't change color, it's not perfect, but :)
|
||||
if let serviceState = maybeServiceState {
|
||||
@ -29,6 +29,6 @@ extension Reactive where Base: UINavigationController {
|
||||
? Colors.OfflineColor
|
||||
: Colors.OnlineColor
|
||||
}
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,10 +49,10 @@ extension ValidationResult {
|
||||
}
|
||||
|
||||
extension Reactive where Base: UILabel {
|
||||
var validationResult: AnyObserver<ValidationResult> {
|
||||
var validationResult: UIBindingObserver<Base, ValidationResult> {
|
||||
return UIBindingObserver(UIElement: base) { label, result in
|
||||
label.textColor = result.textColor
|
||||
label.text = result.description
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ extension Reactive where Base: UIImageView{
|
||||
return downloadableImageAnimated(nil)
|
||||
}
|
||||
|
||||
func downloadableImageAnimated(_ transitionType:String?) -> AnyObserver<DownloadableImage> {
|
||||
func downloadableImageAnimated(_ transitionType:String?) -> UIBindingObserver<Base, DownloadableImage> {
|
||||
return UIBindingObserver(UIElement: base as UIImageView) { imageView, image in
|
||||
for subview in imageView.subviews {
|
||||
subview.removeFromSuperview()
|
||||
@ -35,7 +35,7 @@ extension Reactive where Base: UIImageView{
|
||||
label.text = "⚠️"
|
||||
imageView.addSubview(label)
|
||||
}
|
||||
}.asObserver()
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -60,7 +60,7 @@ extension ControlTests {
|
||||
extension ControlTests {
|
||||
func testLabel_HasWeakReference() {
|
||||
let variable = Variable<NSAttributedString?>(nil)
|
||||
ensureControlObserverHasWeakReference(UILabel(), { (label: UILabel) -> AnyObserver<NSAttributedString?> in label.rx.attributedText }, { variable.asObservable() })
|
||||
ensureControlObserverHasWeakReference(UILabel(), { (label: UILabel) -> AnyObserver<NSAttributedString?> in label.rx.attributedText.asObserver() }, { variable.asObservable() })
|
||||
}
|
||||
|
||||
func testLabel_NextElementsSetsValue() {
|
||||
@ -77,7 +77,7 @@ extension ControlTests {
|
||||
// UIProgressView
|
||||
extension ControlTests {
|
||||
func testProgressView_HasWeakReference() {
|
||||
ensureControlObserverHasWeakReference(UIProgressView(), { (progressView: UIProgressView) -> AnyObserver<Float> in progressView.rx.progress }, { Variable<Float>(0.0).asObservable() })
|
||||
ensureControlObserverHasWeakReference(UIProgressView(), { (progressView: UIProgressView) -> AnyObserver<Float> in progressView.rx.progress.asObserver() }, { Variable<Float>(0.0).asObservable() })
|
||||
}
|
||||
|
||||
func testProgressView_NextElementsSetsValue() {
|
||||
@ -126,7 +126,7 @@ extension ControlTests {
|
||||
// UIActivityIndicatorView
|
||||
extension ControlTests {
|
||||
func testActivityIndicator_HasWeakReference() {
|
||||
ensureControlObserverHasWeakReference(UIActivityIndicatorView(), { (view: UIActivityIndicatorView) -> AnyObserver<Bool> in view.rx.animating }, { Variable<Bool>(true).asObservable() })
|
||||
ensureControlObserverHasWeakReference(UIActivityIndicatorView(), { (view: UIActivityIndicatorView) -> AnyObserver<Bool> in view.rx.animating.asObserver() }, { Variable<Bool>(true).asObservable() })
|
||||
}
|
||||
|
||||
func testActivityIndicator_NextElementsSetsValue() {
|
||||
|
Loading…
Reference in New Issue
Block a user