Describe the bug
When using .onAppear to set a @State variable, or when setting it in init(), the view gets redrawn repeatedly and the Canvas present in the view gets resized every time the view is resized.
The canvas also get resized slightly every time the view is redrawn for any reason.
To Reproduce
Steps to reproduce the behavior:
Example:
struct TokamakApp: App {
var body: some Scene {
WindowGroup("App") {
ContentView()
}
}
}
struct ContentView: View {
@State var myVar = ""
var body: some View {
HStack {
Canvas(renderer: { gc, size in
print(size)
})
Text(self.myVar)
}.onAppear {
self.myVar = "new val"
}
}
}
Expected behavior
The Text's value should be set to the value once and nothing should happen to the Canvas.
Describe the bug When using
.onAppear
to set a@State
variable, or when setting it ininit()
, the view gets redrawn repeatedly and theCanvas
present in the view gets resized every time the view is resized.The canvas also get resized slightly every time the view is redrawn for any reason.
To Reproduce Steps to reproduce the behavior:
Example:
Expected behavior The
Text
's value should be set to the value once and nothing should happen to theCanvas
.Screenshots
Tokamak running on Safari: https://user-images.githubusercontent.com/62475953/158156032-3841027a-c929-4dae-b0a5-97d8ea4f44d2.mov
SwiftUI (macOS): https://user-images.githubusercontent.com/62475953/158156580-9969ac1a-b73e-4a79-98eb-aab18b0005de.mov
Desktop (please complete the following information):