Hi, I have been trying to make a profile page with an edit button that allows the user to change their name, bio, etc. When I close the edit window, the name does not update. However, if I restart the app, the name changes to the updated (and @AppStorage stored) name variable.
How do I make the string containing "Hi, I'm (savedName variable)" update after changing it in the edit window? Here's my code:
struct ProfilePage: View {
@State var showingSheet = false
var body: some View {
VStack {
HStack {
Text("Hi, I'm \(ProfileEditPage().savedName)")
.font(.title)
Spacer()
Button(action: { self.showingSheet.toggle()}) {
Text("Edit")
}
.sheet(isPresented: $showingSheet) {
ProfileEditPage()
}
}
.padding(/@START_MENU_TOKEN@/.top, 50.0/@END_MENU_TOKEN@/)
Divider()
.overlay(.green)
HStack {
Text("Bio")
.font(.title)
.padding(/@START_MENU_TOKEN@/.top, 20.0/@END_MENU_TOKEN@/)
Spacer()
}
HStack {
Text("temp text")
.padding(/@START_MENU_TOKEN@/.top, -10.0/@END_MENU_TOKEN@/)
Spacer()
}
Spacer()
}
.padding(/@START_MENU_TOKEN@/.horizontal, 40.0/@END_MENU_TOKEN@/)
}
}