Skip to content

Instantly share code, notes, and snippets.

@benigumocom
Last active March 23, 2024 21:49
Show Gist options
  • Save benigumocom/e70a029925e61765352c1129526a6d0c to your computer and use it in GitHub Desktop.
Save benigumocom/e70a029925e61765352c1129526a6d0c to your computer and use it in GitHub Desktop.
【SwiftUI】View の 強制再描画 👉 https://android.benigumo.com/20240324/force-redraw/
import SwiftUI
struct TestView: View {
@State var id = false
var body: some View {
AutoProgressView()
.padding()
.id(id)
Button("restart") {
id.toggle()
}
.buttonStyle(.borderedProminent)
}
}
struct AutoProgressView: View {
@State private var value = 0.0
private let total = 10.0
private let duration = 1.0
var body: some View {
ProgressView(value: value, total: total)
.task {
while value < total {
try? await Task.sleep(for: .seconds(duration))
value += duration
}
}
}
}
#Preview {
TestView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment