Skip to content

Commit 890627d

Browse files
committed
some fix
- layout extension fix - deleted unused code - deleted backgroundColor and barColor
1 parent 8f3e2a3 commit 890627d

File tree

2 files changed

+16
-43
lines changed

2 files changed

+16
-43
lines changed

Sources/ComponentsKit/Components/Slider/Models/SliderVM.swift

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,7 @@ extension SliderVM {
7878
return 4
7979
}
8080
var handleOverlaySide: CGFloat {
81-
12
82-
}
83-
var backgroundColor: UniversalColor {
84-
switch style {
85-
case .light:
86-
return self.color.background
87-
case .striped:
88-
return self.color.main
89-
}
90-
}
91-
var barColor: UniversalColor {
92-
switch style {
93-
case .light:
94-
return self.color.main
95-
case .striped:
96-
return self.color.contrast
97-
}
81+
return 12
9882
}
9983
private func stripesCGPath(in rect: CGRect) -> CGMutablePath {
10084
let stripeWidth: CGFloat = 2
@@ -148,31 +132,24 @@ extension SliderVM {
148132
}
149133
}
150134

151-
public extension SliderVM {
152-
var sliderHeight: CGFloat {
153-
self.trackHeight
154-
}
155-
135+
extension SliderVM {
156136
var containerHeight: CGFloat {
157137
max(self.handleSize.height, self.trackHeight)
158138
}
159139

160-
func leftWidth(for totalWidth: CGFloat, progress: CGFloat) -> CGFloat {
161-
let sliderWidth = max(0, totalWidth - self.handleSize.width - 2 * self.trackSpacing)
162-
return sliderWidth * progress
163-
}
164-
165-
func rightWidth(for totalWidth: CGFloat, progress: CGFloat) -> CGFloat {
166-
let sliderWidth = max(0, totalWidth - self.handleSize.width - 2 * self.trackSpacing)
167-
return sliderWidth - self.leftWidth(for: totalWidth, progress: progress)
140+
private func sliderWidth(for totalWidth: CGFloat) -> CGFloat {
141+
max(0, totalWidth - self.handleSize.width - 2 * self.trackSpacing)
168142
}
169143

170144
func barWidth(for totalWidth: CGFloat, progress: CGFloat) -> CGFloat {
171-
self.leftWidth(for: totalWidth, progress: progress)
145+
let width = self.sliderWidth(for: totalWidth)
146+
return width * progress
172147
}
173148

174149
func backgroundWidth(for totalWidth: CGFloat, progress: CGFloat) -> CGFloat {
175-
self.rightWidth(for: totalWidth, progress: progress)
150+
let width = self.sliderWidth(for: totalWidth)
151+
let filled = width * progress
152+
return width - filled
176153
}
177154
}
178155

Sources/ComponentsKit/Components/Slider/SUSlider.swift

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,14 @@ public struct SUSlider: View {
3232

3333
public var body: some View {
3434
GeometryReader { geometry in
35-
let containerHeight = self.model.containerHeight
36-
let sliderHeight = self.model.sliderHeight
37-
3835
let barWidth = self.model.barWidth(for: geometry.size.width, progress: self.progress)
3936
let backgroundWidth = self.model.backgroundWidth(for: geometry.size.width, progress: self.progress)
4037

4138
HStack(spacing: self.model.trackSpacing) {
4239
// Progress segment
43-
RoundedRectangle(cornerRadius: self.model.cornerRadius(for: sliderHeight))
40+
RoundedRectangle(cornerRadius: self.model.cornerRadius(for: self.model.trackHeight))
4441
.foregroundStyle(self.model.color.main.color)
45-
.frame(width: barWidth, height: sliderHeight)
42+
.frame(width: barWidth, height: self.model.trackHeight)
4643

4744
// Handle
4845
RoundedRectangle(cornerRadius: self.model.cornerRadius(for: self.model.handleSize.height))
@@ -75,23 +72,22 @@ public struct SUSlider: View {
7572
Group {
7673
switch self.model.style {
7774
case .light:
78-
RoundedRectangle(cornerRadius: self.model.cornerRadius(for: sliderHeight))
79-
.foregroundStyle(self.model.backgroundColor.color)
75+
RoundedRectangle(cornerRadius: self.model.cornerRadius(for: self.model.trackHeight))
76+
.foregroundStyle(self.model.color.background.color)
8077
.frame(width: backgroundWidth)
81-
8278
case .striped:
8379
ZStack {
84-
RoundedRectangle(cornerRadius: self.model.cornerRadius(for: sliderHeight))
80+
RoundedRectangle(cornerRadius: self.model.cornerRadius(for: self.model.trackHeight))
8581
.foregroundStyle(self.model.color.contrast.color)
8682

8783
StripesShapeSlider(model: self.model)
8884
.foregroundStyle(self.model.color.main.color)
89-
.cornerRadius(self.model.cornerRadius(for: sliderHeight))
85+
.cornerRadius(self.model.cornerRadius(for: self.model.trackHeight))
9086
}
9187
.frame(width: backgroundWidth)
9288
}
9389
}
94-
.frame(height: sliderHeight)
90+
.frame(height: self.model.trackHeight)
9591
}
9692
}
9793
.frame(height: self.model.containerHeight)

0 commit comments

Comments
 (0)