Skip to content

Commit 4798c18

Browse files
committed
proxy work
1 parent 882f7a5 commit 4798c18

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

Sources/LindenmayerViews/ViewComponents/StateSelectorView.swift

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
//
77

88
import Lindenmayer
9-
import SwiftUI
9+
@preconcurrency import SwiftUI
1010

1111
/// A view that provides a visual representation of the states of an L-system and allows the person viewing it to select an index position from that L-system's state.
1212
@available(macOS 12.0, iOS 15.0, *)
13+
@MainActor
1314
public struct StateSelectorView: View {
1415
@State var system: LindenmayerSystem
1516
let _withDetailView: Bool
@@ -108,10 +109,14 @@ public struct StateSelectorView: View {
108109
forwardTimer?.invalidate()
109110
// or fastforward has started to start the timer
110111
reverseTimer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true, block: { _ in
111-
if sliderPosition >= 1.0 {
112-
sliderPosition -= 1
113-
indexPosition -= 1
114-
proxy.scrollTo(indexPosition)
112+
Task {
113+
await MainActor.run {
114+
if sliderPosition >= 1.0 {
115+
sliderPosition -= 1
116+
indexPosition -= 1
117+
proxy.scrollTo(indexPosition)
118+
}
119+
}
115120
}
116121
})
117122
})
@@ -162,10 +167,14 @@ public struct StateSelectorView: View {
162167
reverseTimer?.invalidate()
163168
// or fastforward has started to start the timer
164169
forwardTimer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true, block: { _ in
165-
if sliderPosition < Double(system.state.count - 1) {
166-
sliderPosition += 1
167-
indexPosition += 1
168-
proxy.scrollTo(indexPosition)
170+
Task {
171+
await MainActor.run {
172+
if sliderPosition < Double(system.state.count - 1) {
173+
sliderPosition += 1
174+
indexPosition += 1
175+
proxy.scrollTo(indexPosition)
176+
}
177+
}
169178
}
170179
})
171180
})

0 commit comments

Comments
 (0)