3

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()
}

Boeggles
  • 59
  • 1
  • 6
  • I have the same issue as you. I can't seem to perfectly reproduce it either. Mainly occurs when I'm on the deep linked screen, then click another deep link it does the bounce dance. Using Custom URL Schemes iOS 14. – NeedHelp101 May 04 '21 at 23:49
  • Perhaps it's due to setting the isActive binding on the @Main App. When the deep link opens again, the binding gets reset back to default. Just a guess though – NeedHelp101 May 04 '21 at 23:53
  • Did you find a resolution? – lcj Sep 23 '22 at 18:01

0 Answers0