Skip to content

Commit 8fadf28

Browse files
committed
support trait changes in ShapeDrawingNode
1 parent 33a0adc commit 8fadf28

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

Sources/Components/Compositions/ShapeDrawingNode.swift

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public final class ShapeDrawingNode: ASDisplayNode, ShapeDisplaying {
3434
var shapePath: UIBezierPath?
3535
var shapeLineWidth: CGFloat = 0
3636
var shapeStrokeColor: UIColor?
37+
var userInterfaceStyle: UIUserInterfaceStyle = .light
3738
}
3839

3940
private final class ParameterBox: NSObject {
@@ -104,17 +105,38 @@ public final class ShapeDrawingNode: ASDisplayNode, ShapeDisplaying {
104105
let backing = parameter.backing
105106

106107
guard let path = backing.shapePath else { return }
107-
108+
109+
let userInterfaceStyle = backing.userInterfaceStyle
110+
108111
path.lineWidth = backing.shapeLineWidth
109112

110-
backing.shapeFillColor?.setFill()
113+
backing.shapeFillColor?
114+
.resolvedColor(with: .init(userInterfaceStyle: userInterfaceStyle))
115+
.setFill()
116+
111117
path.fill()
112118

113-
backing.shapeStrokeColor?.setStroke()
119+
backing.shapeStrokeColor?
120+
.resolvedColor(with: .init(userInterfaceStyle: userInterfaceStyle))
121+
.setStroke()
114122

115123
path.stroke()
116124

117125
}
118-
126+
127+
public override func asyncTraitCollectionDidChange(
128+
withPreviousTraitCollection previousTraitCollection: ASPrimitiveTraitCollection
129+
) {
130+
super.asyncTraitCollectionDidChange(withPreviousTraitCollection: previousTraitCollection)
131+
let userInterfaceStyle = asyncTraitCollection().userInterfaceStyle
132+
guard
133+
self.backing.userInterfaceStyle != userInterfaceStyle
134+
else {
135+
return
136+
}
137+
self.backing.userInterfaceStyle = userInterfaceStyle
138+
}
139+
140+
119141
}
120142

0 commit comments

Comments
 (0)