Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

NavigationLink in the resultContent can’t be clicked in. #12

Closed
NiallLDY opened this issue Feb 3, 2021 · 3 comments
Closed

NavigationLink in the resultContent can’t be clicked in. #12

NiallLDY opened this issue Feb 3, 2021 · 3 comments
Labels
wontfix This will not be worked on

Comments

@NiallLDY
Copy link

NiallLDY commented Feb 3, 2021

No description provided.

@sherwinzadeh
Copy link

I'm having the same problem. My guess is that it's because UISearchController is presented modally and there is no UINavigationController for NagivationLinks to work. But I'm not sure...

@NiallLDY
Copy link
Author

NiallLDY commented Feb 4, 2021

I'm having the same problem. My guess is that it's because UISearchController is presented modally and there is no UINavigationController for NagivationLinks to work. But I'm not sure...

So, any ideas to solve this problem?😂

@thislooksfun
Copy link
Owner

Thanks for bringing this to my attention. Unfortunately, it seems that this is a limitation of how UISearchController presents its searchResultsController and how that interacts with SwiftUI. As such I can't fix it.

If you want a workaround you could wrap your view in a custom conditional, like so:

struct ContentView: View {
    @State
    var searchText: String = ""

    var body: some View {
        NavigationView {
            ZStack {
                if searchText.isEmpty {
                    NormalView()
                } else {
                    SearchResultsView(text: searchText)
                }
            }
            .navigationBarSearch($searchText)
        }
    }
}

struct NormalView: View {
    var body: some View {
        Text("Some view")
    }
}

struct SearchResultsView: View {
    var text: String

    var body: some View {
        VStack {
            Text("You searched for \(text)")
            NavigationLink(destination: Text(text)) {
                Text("Let's go!")
            }
        }
    }
}

@thislooksfun thislooksfun added the wontfix This will not be worked on label Feb 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants