Post

Replies

Boosts

Views

Activity

Reply to SwiftUI NavigationLink pops out by itself
For me, my NavigationLinks were popping out whenever the app enters background, e.g. going back to iOS home screen or activating Control Center. I had found that I had an idle @Environment(\.scenePhase) var scenePhase in my App struct, that seem to be causing the uncommanded popping of the NavigationLink. Once I removed the scenePhase the problem was gone.
Nov ’21
Reply to "UI unresponsiveness" warning on @main
I have written a simple View to help anyone trying to isolate this issue that I discovered while trying to find the source of this warning. In my instance, I am using WKWebView to load specific sites that seems to trigger the warning when load(_ request: URLRequest) method is called. import SwiftUI import WebKit struct WebView: UIViewRepresentable { typealias UIViewType = WKWebView let webView: WKWebView func makeUIView(context: Context) -> WKWebView { return self.webView } func updateUIView(_ uiView: WKWebView, context: Context) { } } struct TestView: View { let webView = WKWebView(frame: .zero) var body: some View { ZStack { WebView(webView: self.webView) Button("Test", action: { Task.detached(priority: .background) { await self.webView.load(URLRequest(url: URL(string: "https://www.apple.com")!)) } }) } } } Even when attaching the load(_ request: URLRequest) method to a background thread seems to cause the warning. I am not expert in SwiftUI or the new Concurrency methods, but is there a 'proper' why that this method is supposed to be called off the main thread?
Sep ’22