iOS 17 SwiftUI sheet immediately dismisses after opening

Hi there!

I've noticed a bug that only happens in iOS 17+ where I have a sheet that automatically gets dismissed once it's opened. I'm using .sheet(isPresented:). I've done plenty of troubleshooting using print statements and the boolean isn't getting reset to false until after the sheet gets dismissed.

The odd part is that I have this same sheet other places in my app and it's not getting dismissed.

I was thinking my view is being redrawn and that sets my boolean back to false (which is it's initial state). But it's strange this doesn't seem to be the case. Like I said, using print statements I was able to determine that the bool isn't being set to false until after the sheet dismisses.

I've tried instead of having this @State bool, making it a binding bool that gets passed into my view as false and that doesn't help.

I can't post the code because my company won't let me. Is anyone else having this experience? I see other posts about iOS 17 sheet issues but it doesn't quite seem to be the same thing I'm experiencing.

I just wanted to bring this to Apple's attention. This completely broke my apps functionality.

Given this works in other places in the app, it's more than likely you've done something wrong - and it's not Apple's fault. Remove everything you don't need from that broken bit until it works.

Since you won't post any code we can't help you to see where you're going wrong. Sorry.

@darkpaw So I was able to find out that a chunk of code in my viewModel's loadData() function is what's causing this issue. loadData() gets called only once and it's when the view appears. The code in question has nothing to do with the sheet code @Published var so I don't understand why it's causing the issue. But if I comment this out it works as I would expect. For reference shareImage is not a @Published var.

I understand you saying you think I'm doing something "wrong" but why would it work on devices that aren't running iOS 17? I don't understand what changed.

if let shareImageString = response.images?.first, let shareUrl = URL(string: shareImageString) {
					URLSession.shared.dataTask(with: shareUrl) { [weak self] data, _, _ in
						guard let data = data, let self = self else { return }
						if let uiImage = UIImage(data: data) {
							self.shareImage = uiImage
						}
					}.resume()
				}

@darkpaw This is the sheet code. There is a button which toggles showWebsite to true once the user taps it. WebView is a UIViewRepresentable wrapper on a WKWebView. But the same thing happens even if I just use a Text view as well.

.sheet(isPresented: $showWebsite) {
				if let url = URL(string: viewModel.website) {
					WebView(url: url)
				}
			}

Were you able to find a solution to this? Thank you

iOS 17 SwiftUI sheet immediately dismisses after opening
 
 
Q