Switching Views Worked in Image, bug not in WebView

Viewed 23

The code sample is here. Sample Code

As the demo video showed, I had created an IndexView, when I clicked the view in IndexView, the main view changed to the clicked view.

This worked fine with Image. However, when I use a WebView, which was a NSViewRepresentable with a WKWebView. The main view only changed once and never changed again.

Any idea?

issue

1 Answers

You don't need state wrapper in this case (it is for internal usage). Instead use just regular property - it will indicate differences between views, so force update.

struct WebView:NSViewRepresentable, Equatable, Identifiable {

    // ...    

    let url: URL      // << here !!

Tested with Xcode 13.4 / macOS 12.4

Related