-1

I'm trying to implement native SwiftUI search for my Dictionary screen. The goal is simply to make .searchable show the system search UI (either the expanding tab-bar search, or the regular navigation search), and bind the text into my DictionaryView.

However, the search UI never appears at all.

Even if I attach:

.searchable(text: $searchText)

directly inside the DictionaryView, the search bar still does not show.

And if I attach .searchable at the TabView level using a Search tab with role: .search, tapping that tab also does nothing — the native expanding search experience never activates.

Here is my setup:
MainTabbedView.swift

struct MainTabbedView: View {
    @State private var searchText = ""

    var body: some View {
        TabView {
            Tab("Translate", systemImage: "bubbles.and.sparkles") {
                TranslateView()
            }

            Tab("Keyboard", systemImage: "keyboard") {
                KeyboardView(onReturnFromSettings: {})
            }

            Tab("Dictionary", systemImage: "text.book.closed") {
                NavigationStack {
                    DictionaryView(searchText: $searchText)
                }
            }

            Tab("Search", systemImage: "magnifyingglass", role: .search) {
                NavigationStack { EmptyView() }
            }
        }
        .searchable(text: $searchText) // <-- search never appears
    }
}

DictionaryView.swift

PasteBin link: https://pastebin.com/DAKp26JV

What I expect

  • If .searchable is applied to the TabView, the tab bar’s native search UI should expand normally.

  • If I put .searchable inside DictionaryView, I should at least get a normal search field in the navigation bar.

  • Either way, the search UI should appear somewhere.

What actually happens

  • Nothing appears.

  • The search UI never shows.

  • NavigationStack never displays a search bar.

  • The Search tab never triggers the native expanding search.

So at this point, my search simply does not function at all, regardless of where I attach .searchable.

Question

What prevents .searchable from showing or activating in this setup?
Is there something in my view hierarchy (ZStack overlays, modifiers, nested NavigationStack, etc.) that blocks SwiftUI from displaying the search UI?

And what is the correct way to implement native search so that DictionaryView can finally receive search text?

New contributor
Ikhwan Pramuditha is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
3
  • 1
    Your question should be self-contained. Please include a minimal reproducible example directly in your question, not on pastebin. Someone should be able to directly copy and paste it into a new project and reproduce the issue. Commented Nov 15 at 23:56
  • Replacing DictionaryView with a simple Text, I cannot reproduce your problem. The search bar expands as expected, and an empty search tab appears as expected.Do you mean you want the search button to navigate to the dictionary tab instead? Then the dictionary tab should have role: .search, shouldn't it? Commented Nov 16 at 0:01
  • My main goal is to have the native search UI appear and operate inside DictionaryView. I have tried to wrap the view using NavigationStack/NavigationView but it still doesn't appear. The global search is an alternative way because I'm frustrated with the main goal XD Commented Nov 16 at 4:03

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.