Skip to content

Commit c330916

Browse files
Merge pull request #38 from componentskit/improve-universal-color
Remove `colorScheme` param from `UniversalColor.color`
2 parents 8f12cc8 + 7b406ef commit c330916

File tree

12 files changed

+34
-84
lines changed

12 files changed

+34
-84
lines changed

Examples/DemosApp/DemosApp/ComponentsPreview/Helpers/PreviewWrapper.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ struct PreviewWrapper<Content: View>: View {
55
let title: String
66
@ViewBuilder let content: () -> Content
77

8-
@Environment(\.colorScheme) private var colorScheme
9-
108
var body: some View {
119
ZStack(alignment: Alignment(horizontal: .leading, vertical: .top)) {
1210
self.content()
@@ -21,8 +19,8 @@ struct PreviewWrapper<Content: View>: View {
2119
LinearGradient(
2220
gradient: Gradient(
2321
colors: [
24-
UniversalColor.blue.color(for: self.colorScheme),
25-
UniversalColor.purple.color(for: self.colorScheme),
22+
UniversalColor.blue.color,
23+
UniversalColor.purple.color,
2624
]
2725
),
2826
startPoint: .topLeading,

Examples/DemosApp/DemosApp/Demos/Login/SwiftUILogin.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ struct SwiftUILogin: View {
3434
)
3535
}
3636

37-
@Environment(\.colorScheme) var colorScheme
38-
3937
var body: some View {
4038
ZStack {
41-
UniversalColor.background.color(for: self.colorScheme)
39+
UniversalColor.background.color
4240

4341
ScrollView {
4442
VStack(spacing: 20) {

Sources/ComponentsKit/Components/Button/SUButton.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ private struct CustomButtonStyle: SwiftUI.ButtonStyle {
6262
.padding(.trailing, self.model.horizontalPadding)
6363
.frame(maxWidth: self.model.width)
6464
.frame(height: self.model.height)
65-
.foregroundStyle(self.model.foregroundColor.color(for: self.colorScheme))
65+
.foregroundStyle(self.model.foregroundColor.color)
6666
.background(
67-
self.model.backgroundColor?.color(for: self.colorScheme) ?? Color.clear
67+
self.model.backgroundColor?.color ?? Color.clear
6868
)
6969
.clipShape(
7070
RoundedRectangle(
@@ -76,7 +76,7 @@ private struct CustomButtonStyle: SwiftUI.ButtonStyle {
7676
cornerRadius: self.model.cornerRadius.value()
7777
)
7878
.stroke(
79-
self.model.borderColor?.color(for: self.colorScheme) ?? .clear,
79+
self.model.borderColor?.color ?? .clear,
8080
lineWidth: self.model.borderWidth
8181
)
8282
}

Sources/ComponentsKit/Components/Checkbox/SUCheckbox.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public struct SUCheckbox: View {
1212

1313
@State private var checkmarkStroke: CGFloat
1414
@State private var borderOpacity: CGFloat
15-
@Environment(\.colorScheme) private var colorScheme
1615

1716
// MARK: Initialization
1817

@@ -35,7 +34,7 @@ public struct SUCheckbox: View {
3534
public var body: some View {
3635
HStack(spacing: self.model.spacing) {
3736
ZStack {
38-
self.model.backgroundColor.color(for: self.colorScheme)
37+
self.model.backgroundColor.color
3938
.clipShape(
4039
RoundedRectangle(cornerRadius: self.model.checkboxCornerRadius)
4140
)
@@ -66,12 +65,12 @@ public struct SUCheckbox: View {
6665
lineCap: .round,
6766
lineJoin: .round
6867
))
69-
.foregroundStyle(self.model.foregroundColor.color(for: self.colorScheme))
68+
.foregroundStyle(self.model.foregroundColor.color)
7069
}
7170
.overlay {
7271
RoundedRectangle(cornerRadius: self.model.checkboxCornerRadius)
7372
.stroke(
74-
self.model.borderColor.color(for: self.colorScheme),
73+
self.model.borderColor.color,
7574
lineWidth: self.model.borderWidth
7675
)
7776
.opacity(self.borderOpacity)
@@ -84,7 +83,7 @@ public struct SUCheckbox: View {
8483

8584
if let title = self.model.title {
8685
Text(title)
87-
.foregroundStyle(self.model.titleColor.color(for: self.colorScheme))
86+
.foregroundStyle(self.model.titleColor.color)
8887
.font(self.model.titleFont.font)
8988
}
9089
}

Sources/ComponentsKit/Components/Countdown/SUCountdown.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ public struct SUCountdown: View {
1212
/// The countdown manager handling the countdown logic.
1313
@StateObject private var manager = CountdownManager()
1414

15-
@Environment(\.colorScheme) private var colorScheme
16-
1715
// MARK: - Initializer
1816

1917
/// Initializer.
@@ -86,7 +84,7 @@ public struct SUCountdown: View {
8684
private var colonView: some View {
8785
Text(":")
8886
.font(self.model.preferredMainFont.font)
89-
.foregroundColor(self.model.colonColor.color(for: self.colorScheme))
87+
.foregroundColor(self.model.colonColor.color)
9088
}
9189

9290
private func lightStyledTime(
@@ -97,7 +95,7 @@ public struct SUCountdown: View {
9795
.frame(minHeight: self.model.lightBackgroundMinHight)
9896
.frame(minWidth: self.model.lightBackgroundMinWidth)
9997
.background(RoundedRectangle(cornerRadius: 8)
100-
.fill(self.model.backgroundColor.color(for: self.colorScheme))
98+
.fill(self.model.backgroundColor.color)
10199
)
102100
}
103101
}

Sources/ComponentsKit/Components/Divider/SUDivider.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ public struct SUDivider: View {
77
/// A model that defines the appearance properties.
88
public var model: DividerVM
99

10-
@Environment(\.colorScheme) private var colorScheme
11-
1210
// MARK: - Initialization
1311

1412
/// Initializer.
@@ -22,7 +20,7 @@ public struct SUDivider: View {
2220

2321
public var body: some View {
2422
Rectangle()
25-
.fill(self.model.lineColor.color(for: self.colorScheme))
23+
.fill(self.model.lineColor.color)
2624
.frame(
2725
maxWidth: self.model.orientation == .vertical ? self.model.lineSize : nil,
2826
maxHeight: self.model.orientation == .horizontal ? self.model.lineSize : nil

Sources/ComponentsKit/Components/InputField/SUInputField.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ public struct SUInputField<FocusValue: Hashable>: View {
2626
/// text inputs and input fields within the same view can be independently focused based on the shared `globalFocus`.
2727
public var localFocus: FocusValue
2828

29-
@Environment(\.colorScheme) private var colorScheme
30-
3129
// MARK: Initialization
3230

3331
/// Initializer.
@@ -61,18 +59,18 @@ public struct SUInputField<FocusValue: Hashable>: View {
6159
if self.model.isSecureInput {
6260
SecureField(text: self.$text, label: {
6361
Text(self.model.placeholder ?? "")
64-
.foregroundStyle(self.model.placeholderColor.color(for: self.colorScheme))
62+
.foregroundStyle(self.model.placeholderColor.color)
6563
})
6664
} else {
6765
TextField(text: self.$text, label: {
6866
Text(self.model.placeholder ?? "")
69-
.foregroundStyle(self.model.placeholderColor.color(for: self.colorScheme))
67+
.foregroundStyle(self.model.placeholderColor.color)
7068
})
7169
}
7270
}
73-
.tint(self.model.tintColor.color(for: self.colorScheme))
71+
.tint(self.model.tintColor.color)
7472
.font(self.model.preferredFont.font)
75-
.foregroundStyle(self.model.foregroundColor.color(for: self.colorScheme))
73+
.foregroundStyle(self.model.foregroundColor.color)
7674
.focused(self.$globalFocus, equals: self.localFocus)
7775
.disabled(!self.model.isEnabled)
7876
.keyboardType(self.model.keyboardType)
@@ -82,7 +80,7 @@ public struct SUInputField<FocusValue: Hashable>: View {
8280
}
8381
.padding(.horizontal, self.model.horizontalPadding)
8482
.frame(height: self.model.height)
85-
.background(self.model.backgroundColor.color(for: self.colorScheme))
83+
.background(self.model.backgroundColor.color)
8684
.onTapGesture {
8785
self.globalFocus = self.localFocus
8886
}

Sources/ComponentsKit/Components/Loading/SULoading.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public struct SULoading: View {
99
public var model: LoadingVM
1010

1111
@State private var rotationAngle: CGFloat = 0.0
12-
@Environment(\.colorScheme) private var colorScheme
1312

1413
// MARK: Initialization
1514

@@ -34,7 +33,7 @@ public struct SULoading: View {
3433
}
3534
.trim(from: 0, to: 0.75)
3635
.stroke(
37-
self.model.color.main.color(for: self.colorScheme),
36+
self.model.color.main.color,
3837
style: StrokeStyle(
3938
lineWidth: self.model.loadingLineWidth,
4039
lineCap: .round,

Sources/ComponentsKit/Components/RadioGroup/SwiftUI/SURadioGroup.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public struct SURadioGroup<ID: Hashable>: View {
1111
@Binding public var selectedId: ID?
1212

1313
@State private var viewSizes: [ID: CGSize] = [:]
14-
@Environment(\.colorScheme) private var colorScheme
1514
@State private var tappingId: ID?
1615

1716
// MARK: Initialization
@@ -37,14 +36,14 @@ public struct SURadioGroup<ID: Hashable>: View {
3736
ZStack {
3837
Circle()
3938
.strokeBorder(
40-
self.model.radioItemColor(for: item, isSelected: self.selectedId == item.id).color(for: self.colorScheme),
39+
self.model.radioItemColor(for: item, isSelected: self.selectedId == item.id).color,
4140
lineWidth: self.model.lineWidth
4241
)
4342
.frame(width: self.model.circleSize, height: self.model.circleSize)
4443
if self.selectedId == item.id {
4544
Circle()
4645
.fill(
47-
self.model.radioItemColor(for: item, isSelected: true).color(for: self.colorScheme)
46+
self.model.radioItemColor(for: item, isSelected: true).color
4847
)
4948
.frame(width: self.model.innerCircleSize, height: self.model.innerCircleSize)
5049
.transition(.scale)
@@ -54,9 +53,7 @@ public struct SURadioGroup<ID: Hashable>: View {
5453
.scaleEffect(self.tappingId == item.id ? self.model.animationScale.value : 1.0)
5554
Text(item.title)
5655
.font(self.model.preferredFont(for: item.id).font)
57-
.foregroundColor(
58-
self.model.textColor(for: item).color(for: self.colorScheme)
59-
)
56+
.foregroundColor(self.model.textColor(for: item).color)
6057
}
6158
.background(
6259
GeometryReader { proxy in

Sources/ComponentsKit/Components/SegmentedControl/SUSegmentedControl.swift

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public struct SUSegmentedControl<ID: Hashable>: View {
1111
@Binding public var selectedId: ID
1212

1313
@Namespace private var animationNamespace
14-
@Environment(\.colorScheme) private var colorScheme
1514

1615
// MARK: Initialization
1716

@@ -35,12 +34,8 @@ public struct SUSegmentedControl<ID: Hashable>: View {
3534
Text(itemVM.title)
3635
.lineLimit(1)
3736
.font(self.model.preferredFont(for: itemVM.id).font)
38-
.foregroundStyle(self.model
39-
.foregroundColor(
40-
id: itemVM.id,
41-
selectedId: self.selectedId
42-
)
43-
.color(for: self.colorScheme)
37+
.foregroundStyle(
38+
self.model.foregroundColor(id: itemVM.id, selectedId: self.selectedId).color
4439
)
4540
.frame(maxWidth: self.model.width, maxHeight: self.model.height)
4641
.padding(.horizontal, self.model.horizontalInnerPaddings)
@@ -57,9 +52,7 @@ public struct SUSegmentedControl<ID: Hashable>: View {
5752
RoundedRectangle(
5853
cornerRadius: self.model.selectedSegmentCornerRadius()
5954
)
60-
.fill(self.model.selectedSegmentColor.color(
61-
for: self.colorScheme
62-
))
55+
.fill(self.model.selectedSegmentColor.color)
6356
.matchedGeometryEffect(
6457
id: "segment",
6558
in: self.animationNamespace
@@ -71,7 +64,7 @@ public struct SUSegmentedControl<ID: Hashable>: View {
7164
}
7265
.padding(.all, self.model.outerPaddings)
7366
.frame(height: self.model.height)
74-
.background(self.model.backgroundColor.color(for: self.colorScheme))
67+
.background(self.model.backgroundColor.color)
7568
.clipShape(
7669
RoundedRectangle(cornerRadius: self.model.cornerRadius.value())
7770
)

0 commit comments

Comments
 (0)