Skip to content

Commit 7883076

Browse files
committed
refactor: updatePositions timing
1 parent 4482708 commit 7883076

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

Example/Example/ContentView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ struct ContentView: View {
1717
id: \.x,
1818
selectedData: $selectedData
1919
)
20-
.frame(height: 300, alignment: .bottom)
20+
.hiddenChart(true)
21+
// .frame(height: 300, alignment: .bottom)
2122
// .hiddenChart(true)
2223
// .minCount(3)
2324
// .graph(width: .ratio(0.8), height: .fixed(50))

Sources/GraphRangeSlider/GraphRangeSlider.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,22 @@ public struct GraphRangeSlider<Data, ID>: View where Data: RandomAccessCollectio
2828
public var body: some View {
2929
Group {
3030
if isHiddenChart {
31-
if !positions.isEmpty {
32-
Slider(
33-
positions: positions,
34-
onEnded: { builder.onEnded.call(selectedData) },
35-
leftCurrentIndex: $leftCurrentIndex,
36-
rightCurrentIndex: $rightCurrentIndex
37-
)
38-
.frame(height: toggleRadius * 2)
31+
Group {
32+
if !positions.isEmpty {
33+
Slider(
34+
positions: positions,
35+
onEnded: { builder.onEnded.call(selectedData) },
36+
leftCurrentIndex: $leftCurrentIndex,
37+
rightCurrentIndex: $rightCurrentIndex
38+
)
39+
.frame(height: toggleRadius * 2)
40+
}
41+
}
42+
.onAppear {
43+
if positions.isEmpty {
44+
updatePositions()
45+
updateIndices()
46+
}
3947
}
4048
} else {
4149
Chart(data, id: id) { data in

0 commit comments

Comments
 (0)