SwiftUI Deep Link Navigation bouncing

Viewed 242

I've built a deep linking schema with SwiftUI and have it mostly working. The only issue that I'm suffering from is that when I'm in the same tab and in a navigation stack, a deep link that routes to a different view in the same tab causes this weird bouncing effect where it navigates to the main tab, back to the deep linked view then back out.

in the Main tab view I have this code

.onOpenURL { url in
 handleDeepLink(url: url)
}

this goes to the tab and if the deep link is valid it triggers a hidden navigation link

 NavigationLink(destination: CompanyPageView(symbol: deepLinkedCompany), isActive: $isDeepLinkingIn, label: { EmptyView() }).hidden()

this works in most cases but for some reason if I'm already in the tab and inside another navigation link in page, opening a deep link does the bounce thing.

How my navState is :

class NavState: ObservableObject {
    @Published var firstLevel: String? = nil
    var secondLevel: String? = nil
    var thirdLevel: String? = nil
}

Subview

 @EnvironmentObject var navState: NavState
 @Binding var deepLinkedCompany: String

VStack {
    //random view stuff

NavigationLink(destination: CompanyPageView(symbol: deepLinkedCompany), tag: "hoboken" , selection: $navState.firstLevel, label: { EmptyView() }).hidden()
}

 

CompanyPageView

@EnvironmentObject var navState: NavState
@Environment(\.presentationMode) var mode: Binding<PresentationMode>

//view stuff

.onOpenURL{url in
            self.mode.wrappedValue.dismiss()
}

0 Answers
Related