Skip to content

Dismiss @Presents modal but keep state? #3156

Answered by stephencelis
zachwaugh asked this question in Q&A
Discussion options

You must be logged in to vote

@Presents is state-driven, so the nil vs. non-nil state of the wrapped value is what tells SwiftUI to hide vs. show a feature. If you want this state to stick around, you could hold onto the imagePicker as a non-optional, Scope-d child, instead, and then drive navigation using a simple boolean, instead.

If you have multiple destinations, you can remove the associated value from that case, instead. Here's an example refactor of our SyncUps app's detail feature where it preserves the edit "draft":

diff --git a/Examples/SyncUps/SyncUps/SyncUpDetail.swift b/Examples/SyncUps/SyncUps/SyncUpDetail.swift
index b321ee54ac..cecb6fcba9 100644
--- a/Examples/SyncUps/SyncUps/SyncUpDetail.swift
+++ b/E…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@zachwaugh
Comment options

Answer selected by zachwaugh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants