jgale / SwiftUIPresentationModeBug

A reproducible example of how adding @Environment(\.presentationMode) causes sheets to be rendered twice

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SwiftUI presentationMode bug

I was encountering a bug on my app where my View displayed in a sheet was getting initialized twice. I was initializing my ViewModel in that view, which was causing all sorts of problems with multiple network requests firing and my views not updating.

Debugger output:

init sheet
init sheet

I tracked it down to this line in my ContentView:

@Environment(\.presentationMode) var presentation

Removing that line solved my problem.

I had initially added it to workaround some other SwiftUI bug but I found a different workaround for that.

About

A reproducible example of how adding @Environment(\.presentationMode) causes sheets to be rendered twice


Languages

Language:Swift 100.0%