Skip to content

Commit 04c51b6

Browse files
add spacing param to the model and rename unitsPosition to unitsStyle
1 parent ece0bc5 commit 04c51b6

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

Examples/DemosApp/DemosApp/ComponentsPreview/PreviewPages/CountdownPreview.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@ struct CountdownPreview: View {
1313
Form {
1414
ComponentOptionalColorPicker(selection: self.$model.color)
1515
FontPicker(selection: self.$model.font)
16-
SizePicker(selection: self.$model.size)
17-
Picker("Units Position", selection: self.$model.unitsPosition) {
18-
Text("None").tag(CountdownVM.UnitsStyle.hidden)
19-
Text("Bottom").tag(CountdownVM.UnitsStyle.bottom)
20-
Text("Trailing").tag(CountdownVM.UnitsStyle.trailing)
21-
}
22-
Picker("Style", selection: self.$model.style) {
23-
Text("Plain").tag(CountdownVM.Style.plain)
24-
Text("Light").tag(CountdownVM.Style.light)
25-
}
2616
Picker("Locale", selection: self.$model.locale) {
2717
Text("Current").tag(Locale.current)
2818
Text("EN").tag(Locale(identifier: "en"))
@@ -36,6 +26,16 @@ struct CountdownPreview: View {
3626
Text("HI").tag(Locale(identifier: "hi"))
3727
Text("PT").tag(Locale(identifier: "pt"))
3828
}
29+
SizePicker(selection: self.$model.size)
30+
Picker("Style", selection: self.$model.style) {
31+
Text("Plain").tag(CountdownVM.Style.plain)
32+
Text("Light").tag(CountdownVM.Style.light)
33+
}
34+
Picker("Units Style", selection: self.$model.unitsStyle) {
35+
Text("None").tag(CountdownVM.UnitsStyle.hidden)
36+
Text("Bottom").tag(CountdownVM.UnitsStyle.bottom)
37+
Text("Trailing").tag(CountdownVM.UnitsStyle.trailing)
38+
}
3939
DatePicker("Until Date", selection: self.$model.until, in: Date()..., displayedComponents: [.date, .hourAndMinute])
4040
.datePickerStyle(.compact)
4141
}

Sources/ComponentsKit/Countdown/Models/CountdownVM.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ public struct CountdownVM: ComponentVM {
1818
/// Defaults to `.light`.
1919
public var style: Style = .light
2020

21-
/// The position of the units relative to the countdown numbers.
21+
/// The visual style of the units.
2222
///
2323
/// Defaults to `.bottom`.
24-
public var unitsPosition: UnitsStyle = .bottom
24+
public var unitsStyle: UnitsStyle = .bottom
2525

2626
/// The target date until which the countdown runs.
2727
public var until: Date = Date().addingTimeInterval(3600 * 85)
@@ -114,6 +114,14 @@ extension CountdownVM {
114114
var horizontalPadding: CGFloat {
115115
return 4
116116
}
117+
var spacing: CGFloat {
118+
switch self.style {
119+
case .light:
120+
return 10
121+
case .plain:
122+
return 6
123+
}
124+
}
117125
}
118126

119127
extension CountdownVM {
@@ -160,7 +168,7 @@ extension CountdownVM {
160168
let formattedValue = String(format: "%02d", value)
161169
let result = NSMutableAttributedString(string: formattedValue, attributes: mainTextAttributes)
162170

163-
switch self.unitsPosition {
171+
switch self.unitsStyle {
164172
case .hidden:
165173
return result
166174

@@ -189,7 +197,7 @@ extension CountdownVM {
189197

190198
extension CountdownVM {
191199
func shouldRecalculateWidth(_ oldModel: Self) -> Bool {
192-
return self.unitsPosition != oldModel.unitsPosition
200+
return self.unitsStyle != oldModel.unitsStyle
193201
|| self.style != oldModel.style
194202
|| self.preferredFont != oldModel.preferredFont
195203
|| self.size != oldModel.size

Sources/ComponentsKit/Countdown/SUCountdown.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public struct SUCountdown: View {
2626
// MARK: - Body
2727

2828
public var body: some View {
29-
HStack(alignment: .top, spacing: self.model.style == .light ? 10 : 6) {
30-
switch (self.model.style, self.model.unitsPosition) {
29+
HStack(alignment: .top, spacing: self.model.spacing) {
30+
switch (self.model.style, self.model.unitsStyle) {
3131
case (.plain, .bottom):
3232
self.styledTime(value: self.manager.days, unit: .days)
3333
colonView

0 commit comments

Comments
 (0)