Hi,
it seems that I have run into a similar problem as with my other @State
problem.
I have created a small sample project illustrating the issue over here.
It is very similar to the other issue with .fileimporter
, since it is again that a @State
variable does not properly reflect an update done in onAppear
. Below (or in the sample project) is the relevant coding. Unfortunately I have still not enough understanding of the inner workings to fix it myself ;-(...
import Adwaita
@main
struct IssueWithState: App {
let app = AdwaitaApp(id: "de.virtualfridge.issueWithState")
@State private var text = "This will be replaced"
var scene: Scene {
Window(id: "main") { window in
VStack {
Text(Loc.helloWorld)
.padding()
Text(text)
.padding()
.onAppear { text = "Not in extra view struct works" }
OtherView()
.padding()
}
.topToolbar { ToolbarView(app: app, window: window) }
}
.defaultSize(width: 450, height: 300)
}
}
struct OtherView: View {
@State private var text = "This should not be there."
var view: Body {
Text(text)
.padding()
.onAppear { text = "It's good now" }
}
}
Thank you for your support!
Cheers, Michael