NEW: Subscribe to Hacking with Swift+ and accelerate your learning! >>

SOLVED: presentationMode.wrappedValue.dismiss() BREAKS when underlying view is updated

Forums > SwiftUI

Hi

I have ViewA which presents ViewB via a .sheet modifier in ViewA. ViewB uses @Environment(.presentationMode) var presentationmode and presentationMode.wrappedValue.dismiss() to dismiss itself.

This works most of the time.

However, if the underlying ViewA is updated while ViewB is presented (e.g. the device is rotated causing ViewA to update), ViewB's presentationMode.wrappedValue.dismiss() no longer works.

I am using the examples provided by Paul, but cannot find a solution to this problem.

Am I doing something wrong?

Thanks G

   

This problem is solved on iOS 14.2 beta 3 (18B5072f) and iPadOS 14.2 beta 3 (18B5072f).

However, just for anyone experiencing this problem, I found that you should also take care not to update the underlying view (e.g. ViewA) via any mechanism (e.g. timer, etc.) while ViewB is presented. This will cause the presentationMode in ViewB to "detach" from ViewA, thus breaking the dismiss functionality.

If anyone else can explain this better, or has a work around, please comment.

Thanks G

   

Hacking with Swift is sponsored by Fernando Olivares

SPONSORED Ever ask for help and your reviewer immediately notices issues you missed? Fernando Olivares is a 10-year veteran from Big Nerd Ranch and Lambda School who can help hone your app building skills, and he's just launched a new book that does just that – use the code "hacking" to save $5!

Buy the book

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

Not logged in

Log in
 

Link copied to your pasteboard.