Skip to content

Commit

Permalink
Update AnyDisplayNode - more method chains for customization #51
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii authored May 12, 2021
1 parent f7ff421 commit aa9ecf2
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions Sources/Components/Compositions/AnyDisplayNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,26 @@ public typealias FunctionalDisplayNode = AnyDisplayNode

If you need to inject specific props into AnyDisplayNode, you can use `AnyPropsDisplayNode`.
However, this does not affect increasing binary size effectively because it emits symbols of each generic parameter.


```swift
func myNode() -> AnyDisplayNode {

let label = ASTextNode()

return AnyDisplayNode { _, _ in
LayoutSpec {
VStackLayout {
label
}
}
}
}
```
*/
open class AnyDisplayNode: SafeAreaDisplayNode {

private let retainItems: [Any]
private var retainItems: [Any]

private let hook: Hook = .init()

Expand Down Expand Up @@ -84,16 +100,35 @@ open class AnyDisplayNode: SafeAreaDisplayNode {
super.layout()
hook.onLayout(self)
}


@available(*, unavailable)
open override func onDidLoad(_ body: @escaping ASDisplayNodeDidLoadBlock) {
super.onDidLoad(body)
}

@discardableResult
public final func onDidLoad(_ onDidLoad: @escaping (AnyDisplayNode) -> Void) -> Self {
hook.onDidload = onDidLoad
return self
}


@discardableResult
public final func onLayout(_ onLaoyout: @escaping (AnyDisplayNode) -> Void) -> Self {
hook.onLayout = onLaoyout
return self
}

@discardableResult
public final func associate(_ object: Any) -> Self {
retainItems.append(object)
return self
}

@discardableResult
public final func setBackgroundColor(_ color: UIColor) -> Self {
backgroundColor = color
return self
}

}

Expand Down

0 comments on commit aa9ecf2

Please sign in to comment.