Post

Replies

Boosts

Views

Activity

Reply to iOS 17 SwiftUI sheet immediately dismisses after opening
@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) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’23
Reply to iOS 17 SwiftUI sheet immediately dismisses after opening
@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() }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’23