Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Previous view completely reloaded after pop #76

Closed
adku opened this issue Jun 13, 2022 · 1 comment
Closed

Previous view completely reloaded after pop #76

adku opened this issue Jun 13, 2022 · 1 comment

Comments

@adku
Copy link

adku commented Jun 13, 2022

Hello,

For normal Navigation SwiftUI it's possible to dismiss view and still see old data on this view (TextFields etc.)

@Environment(\.presentationMode) var presentationMode
Button { presentationMode.wrappedValue.dismiss() } label: {

For NavigationStack it looks like the view is completely reloaded / restarted / recreated from scratch.
Pop method is not working like a dismiss one. Dismiss method from official SwiftUI is not working at all for NavigationStack views.

Is there any possibility to achieve this kind of behavior?

@adku
Copy link
Author

adku commented Jun 13, 2022

Ok, I found out that this Issue is described with a workaround on the main page. I missed it. We can close this issue or even delete it if it's possible.

Issues
" SwiftUI resets all the properties of a view marked with @State every time the view is removed from a view hierarchy. For the NavigationStackView this is a problem because when I come back to a previous view (with a pop operation) I want all my view controls to be as I left them before (for example I want my TextFields to contain the text I previously typed in). In order to workaround this problem you have to use @observableobject when you need to make some state persist between push/pop operations. For example:
"

@adku adku closed this as completed Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant