Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add additional binder for ASDisplayNode #32

Merged
merged 1 commit into from
Jul 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Example/Tests/ASDisplayNode+RxSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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") {
Expand Down Expand Up @@ -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))
}
}
}
}
18 changes: 18 additions & 0 deletions RxCocoa-Texture/Classes/ASDisplayNode+Rx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ import RxCocoa
import UIKit

extension Reactive where Base: ASDisplayNode {

public var alpha: ASBinder<CGFloat> {
return ASBinder(self.base) { node, alpha in
node.alpha = alpha
}
}

public var backgroundColor: ASBinder<UIColor?> {
return ASBinder(self.base) { node, backgroundColor in
node.backgroundColor = backgroundColor
}
}

public var didLoad: Observable<Void> {

Expand All @@ -25,6 +37,12 @@ extension Reactive where Base: ASDisplayNode {
node.isHidden = isHidden
}
}

public var isUserInteractionEnabled: ASBinder<Bool> {
return ASBinder(self.base) { node, isUserInteractionEnabled in
node.isUserInteractionEnabled = isUserInteractionEnabled
}
}

public var setNeedsLayout: Binder<Void> {

Expand Down