|
6 | 6 | // |
7 | 7 |
|
8 | 8 | import Lindenmayer |
9 | | -import SwiftUI |
| 9 | +@preconcurrency import SwiftUI |
10 | 10 |
|
11 | 11 | /// 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. |
12 | 12 | @available(macOS 12.0, iOS 15.0, *) |
| 13 | +@MainActor |
13 | 14 | public struct StateSelectorView: View { |
14 | 15 | @State var system: LindenmayerSystem |
15 | 16 | let _withDetailView: Bool |
@@ -108,10 +109,14 @@ public struct StateSelectorView: View { |
108 | 109 | forwardTimer?.invalidate() |
109 | 110 | // or fastforward has started to start the timer |
110 | 111 | 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 | + } |
115 | 120 | } |
116 | 121 | }) |
117 | 122 | }) |
@@ -162,10 +167,14 @@ public struct StateSelectorView: View { |
162 | 167 | reverseTimer?.invalidate() |
163 | 168 | // or fastforward has started to start the timer |
164 | 169 | 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 | + } |
169 | 178 | } |
170 | 179 | }) |
171 | 180 | }) |
|
0 commit comments