From 8a34c730990c151f660de2ccb3f62ba090631b41 Mon Sep 17 00:00:00 2001 From: Wendy Liga Date: Wed, 17 Jun 2020 09:54:13 +0700 Subject: [PATCH] add additional binder --- Example/Tests/ASDisplayNode+RxSpec.swift | 17 +++++++++++++++++ RxCocoa-Texture/Classes/ASDisplayNode+Rx.swift | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/Example/Tests/ASDisplayNode+RxSpec.swift b/Example/Tests/ASDisplayNode+RxSpec.swift index 13736b4..350ceae 100644 --- a/Example/Tests/ASDisplayNode+RxSpec.swift +++ b/Example/Tests/ASDisplayNode+RxSpec.swift @@ -20,6 +20,7 @@ class ASDisplayNode_RxExtensionSpec: QuickSpec { let node1 = ASDisplayNode() let node2 = ASDisplayNode() let node3 = ASDisplayNode() + let node4 = ASDisplayNode() beforeEach { node1.rx.width.onNext(ASDimension(unit: .points, value: 17.0)) @@ -31,6 +32,10 @@ class ASDisplayNode_RxExtensionSpec: QuickSpec { node2.rx.maxHeight.onNext(ASDimension(unit: .points, value: 20.0)) node3.rx.preferredSize.onNext(CGSize(width: 40.0, height: 40.0)) + + node4.rx.backgroundColor.onNext(.red) + node4.rx.alpha.onNext(0.3) + node4.rx.isUserInteractionEnabled.onNext(false) } it("should has correct width") { @@ -60,6 +65,18 @@ class ASDisplayNode_RxExtensionSpec: QuickSpec { it("should has correct preferredSize") { expect(node3.style.preferredSize).to(equal(CGSize(width: 40.0, height: 40.0))) } + + it("should has correct backgroundColor") { + expect(node4.backgroundColor).to(equal(.red)) + } + + it("should has correct alpha") { + expect(node4.alpha).to(equal(0.3)) + } + + it("should has correct isUserInteractionEnabled") { + expect(node4.isUserInteractionEnabled).to(equal(false)) + } } } } diff --git a/RxCocoa-Texture/Classes/ASDisplayNode+Rx.swift b/RxCocoa-Texture/Classes/ASDisplayNode+Rx.swift index d3ee1e1..08d9d7b 100644 --- a/RxCocoa-Texture/Classes/ASDisplayNode+Rx.swift +++ b/RxCocoa-Texture/Classes/ASDisplayNode+Rx.swift @@ -11,6 +11,18 @@ import RxCocoa import UIKit extension Reactive where Base: ASDisplayNode { + + public var alpha: ASBinder { + return ASBinder(self.base) { node, alpha in + node.alpha = alpha + } + } + + public var backgroundColor: ASBinder { + return ASBinder(self.base) { node, backgroundColor in + node.backgroundColor = backgroundColor + } + } public var didLoad: Observable { @@ -25,6 +37,12 @@ extension Reactive where Base: ASDisplayNode { node.isHidden = isHidden } } + + public var isUserInteractionEnabled: ASBinder { + return ASBinder(self.base) { node, isUserInteractionEnabled in + node.isUserInteractionEnabled = isUserInteractionEnabled + } + } public var setNeedsLayout: Binder {