Pop to root view when selected tab is tapped again for WebKit

Hello everyone!

I have a WKWebView in my swiftui app and would like to enable to "pop root view when selected tab is tapped again" feature, but I have been unable to figure out how to implement this.

Here's the basic code:

class TabIdentifierModel:ObservableObject {
    @Published var tabSelection:TabIdentifier {
        willSet {
            if newValue == tabSelection {
                NotificationCenter.default.post(name: .popRootView, object: nil, userInfo: ["tab": newValue.rawValue])
            }
        }
    }
    
    init() {
        tabSelection = .home
    }
}

struct ContentView: View {
    @AppStorage(AppStorageKeys.enableShorts) var enableShorts = true
    
    @StateObject var storeVM = StoreVM()
    
    @StateObject var downloadURLManager = DownloadURLManager.shared
    @State var downloadViewIsOpen = false

// ......    

    @State var tabSelection = TabIdentifierModel()
    
    var body: some View {
        TabView(selection: $tabSelection.tabSelection) {
          // ......
            
            WebViewWrapper(url: $libraryTabURL)
                .tabItem {
                    Label {
                        Text("Library")
                    } icon: {
                        Image(systemName: "folder.fill")
                    }
                }.tag(TabIdentifier.library)
            
           // ......
        }
        .environmentObject(tabSelection)
    }
}

Tapping on the tab again doesn't seem to set the value again thus the NotificationCenter.default.post is not sent and the web view is not reloaded.

Help would be much appreciated! Thanks in advance!

Pop to root view when selected tab is tapped again for WebKit
 
 
Q