-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathRecursiveLayoutViewController.swift
114 lines (96 loc) · 2.56 KB
/
RecursiveLayoutViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
// RecursiveLayoutViewController.swift
// Demo
//
// Created by Muukii on 2021/01/19.
// Copyright © 2021 muukii. All rights reserved.
//
import Foundation
import GlossButtonNode
import TextureSwiftSupport
import TypedTextAttributes
final class RecursiveLayoutViewController: DisplayNodeViewController {
private let nodes = (0 ..< 10).map { _ in WrapperNode { ElasticNode() } }
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
}
override func layoutSpecThatFits(_: ASSizeRange) -> ASLayoutSpec {
LayoutSpec {
VStackLayout {
nodes
}
}
}
}
extension RecursiveLayoutViewController {
final class ElasticNode: ASDisplayNode {
private let button = GlossButtonNode()
private var flag = false
private let textNode = Mocks.ButtonNode()
private let textNode2 = Mocks.ButtonNode()
override init() {
super.init()
automaticallyManagesSubnodes = true
button.setDescriptor(
.init(
title: "Tap".attributed { TextAttributes() },
bodyStyle: .init(layout: .vertical()),
surfaceStyle: .fill(
.init(
cornerRound: .circle,
backgroundColor: .fill(.white), dropShadow: nil
)
)
),
for: .normal
)
button.onTap = { [weak self] in
guard let self = self else { return }
self.flag.toggle()
#if true
UIViewPropertyAnimator(duration: 0.3, dampingRatio: 1) {
self.setNeedsLayout()
self.layoutIfNeeded()
// self.supernode?.view.window?.setNeedsLayout()
// self.supernode?.view.window?.layoutIfNeeded()
}
.startAnimation()
#else
self.transitionLayout(
withAnimation: true,
shouldMeasureAsync: false,
measurementCompletion: nil
)
// self.supernode?.setNeedsLayout()
// self.supernode?.layoutIfNeeded()
#endif
}
}
// override func animateLayoutTransition(_ context: ASContextTransitioning) {
//
// let a = UIViewPropertyAnimator(duration: 0.3, dampingRatio: 1) {
// self.supernode?.layoutIfNeeded()
// self.layoutIfNeeded()
// }
//
// a.addCompletion { (_) in
// context.completeTransition(true)
// }
//
// a.startAnimation()
//
// }
override func layoutSpecThatFits(_: ASSizeRange) -> ASLayoutSpec {
LayoutSpec {
VStackLayout {
button
textNode
if flag {
textNode2
}
}
}
}
}
}