@@ -23,6 +23,57 @@ fileprivate final class BackingShapeLayerNode : ASDisplayNode {
23
23
return shape
24
24
}
25
25
}
26
+
27
+ fileprivate var shapeStrokeColor : UIColor ? {
28
+ didSet {
29
+ ASPerformBlockOnMainThread {
30
+ CATransaction . begin ( )
31
+ CATransaction . setDisableActions ( true )
32
+ defer {
33
+ CATransaction . commit ( )
34
+ }
35
+ self . layer. strokeColor = self . shapeStrokeColor?
36
+ . resolvedColor ( with: . init( userInterfaceStyle: self . asyncTraitCollection ( ) . userInterfaceStyle) )
37
+ . cgColor
38
+ }
39
+ }
40
+ }
41
+
42
+ public var shapeFillColor : UIColor ? {
43
+ didSet {
44
+ ASPerformBlockOnMainThread {
45
+ CATransaction . begin ( )
46
+ CATransaction . setDisableActions ( true )
47
+ defer {
48
+ CATransaction . commit ( )
49
+ }
50
+ self . layer. fillColor = self . shapeFillColor?
51
+ . resolvedColor ( with: . init( userInterfaceStyle: self . asyncTraitCollection ( ) . userInterfaceStyle) )
52
+ . cgColor
53
+ }
54
+ }
55
+ }
56
+
57
+ override func asyncTraitCollectionDidChange(
58
+ withPreviousTraitCollection previousTraitCollection: ASPrimitiveTraitCollection
59
+ ) {
60
+ super. asyncTraitCollectionDidChange ( withPreviousTraitCollection: previousTraitCollection)
61
+ lazy var userInterfaceStyle = asyncTraitCollection ( ) . userInterfaceStyle
62
+ guard
63
+ isNodeLoaded,
64
+ previousTraitCollection. userInterfaceStyle != userInterfaceStyle
65
+ else {
66
+ return
67
+ }
68
+ ASPerformBlockOnMainThread {
69
+ self . layer. strokeColor = self . shapeStrokeColor?
70
+ . resolvedColor ( with: . init( userInterfaceStyle: userInterfaceStyle) )
71
+ . cgColor
72
+ self . layer. fillColor = self . shapeFillColor?
73
+ . resolvedColor ( with: . init( userInterfaceStyle: userInterfaceStyle) )
74
+ . cgColor
75
+ }
76
+ }
26
77
}
27
78
28
79
/// A node that displays shape with CAShapeLayer
@@ -53,36 +104,22 @@ public final class ShapeLayerNode : ASDisplayNode, ShapeDisplaying {
53
104
setNeedsLayout ( )
54
105
}
55
106
}
56
-
107
+
57
108
public var shapeStrokeColor : UIColor ? {
58
109
get {
59
- return backingNode. layer . strokeColor . map { UIColor ( cgColor : $0 ) }
110
+ return backingNode. shapeStrokeColor
60
111
}
61
112
set {
62
- ASPerformBlockOnMainThread {
63
- CATransaction . begin ( )
64
- CATransaction . setDisableActions ( true )
65
- defer {
66
- CATransaction . commit ( )
67
- }
68
- self . backingNode. layer. strokeColor = newValue? . cgColor
69
- }
113
+ backingNode. shapeStrokeColor = newValue
70
114
}
71
115
}
72
116
73
117
public var shapeFillColor : UIColor ? {
74
118
get {
75
- return backingNode. layer . fillColor . map { UIColor ( cgColor : $0 ) }
119
+ return backingNode. shapeFillColor
76
120
}
77
121
set {
78
- ASPerformBlockOnMainThread {
79
- CATransaction . begin ( )
80
- CATransaction . setDisableActions ( true )
81
- defer {
82
- CATransaction . commit ( )
83
- }
84
- self . backingNode. layer. fillColor = newValue? . cgColor
85
- }
122
+ backingNode. shapeFillColor = newValue
86
123
}
87
124
}
88
125
0 commit comments