Skip to content

Commit 1b9cbfe

Browse files
authored
Refactor view modifiers handling for color and background
1 parent 902db97 commit 1b9cbfe

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

Sources/DynamicUI/Extensions/View.modifiers.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,20 @@ extension View {
116116
) -> some View {
117117
var view = content
118118

119-
if let string = modifiers?["color"]?.toString(),
120-
let color = DynamicUIHelper.translateColor(string) {
121-
view = view.foregroundStyle(color)
122-
}
123-
124-
if let string = modifiers?["background"]?.toString(),
125-
let color = DynamicUIHelper.translateColor(string) {
126-
view = view.background(color)
119+
modifiers?.forEach { key, value in
120+
switch key {
121+
case "color", "foregroundStyle", "foregroundColor":
122+
guard #available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *),
123+
let string = value.toString(),
124+
let color = DynamicUIHelper.translateColor(string) else { break }
125+
view = view.foregroundStyle(color)
126+
127+
case "background", "backgroundColor", "backgroundStyle":
128+
guard #available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *),
129+
let string = value.toString(),
130+
let color = DynamicUIHelper.translateColor(string) else { break }
131+
view = view.background(color)
132+
}
127133
}
128134

129135
view

0 commit comments

Comments
 (0)