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
.searchableis applied to the TabView, the tab bar’s native search UI should expand normally.If I put
.searchableinsideDictionaryView, 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?
DictionaryViewwith a simpleText, 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 haverole: .search, shouldn't it?