How it works
TabSearchActivation describes how a person enters the search experience that a TabView exposes through a search-role tab. When a tab bar includes a dedicated search tab, SwiftUI needs to know what activating search means on a given platform: whether selecting the tab is enough, whether the search field should immediately take focus, or whether to defer to the system's default behavior. You supply one of these activation styles to declare that intent, and SwiftUI coordinates the tab selection and the search field accordingly. Reach for it when you build a TabView whose search tab should behave a particular way on selection rather than relying on the platform default.
Add a search-role tab to the TabView
TabSearchActivation only matters when a TabView actually contains a search destination. You create that destination by giving a Tab the search role, written as
Tab(role: .search), which tells SwiftUI this tab represents the container's search surface rather than ordinary content. The activation style you choose later governs how this particular tab comes alive.Apply the activation style with tabViewSearchActivation(_:)
You attach a TabSearchActivation to the container with the
tabViewSearchActivation(_:)modifier placed on the TabView itself, as in.tabViewSearchActivation(.searchTabSelection). The modifier takes a single TabSearchActivation value and propagates that intent down to the search-role tab, so the whole container shares one consistent answer for what activating search should do.Choose searchTabSelection to activate on selection
The
.searchTabSelectionstyle says that merely selecting the search tab is what activates the search experience — the act of switching to the tab is the trigger. In the example, passing.searchTabSelectionmeans moving to the search-roleTab(role: .search)is treated as the user choosing to search, without requiring a separate gesture inside the tab.Let it coexist with ordinary content tabs
TabSearchActivation governs only the search tab; the other tabs are unaffected and keep their normal selection behavior. Here the
Tab("Home", systemImage: "house")andTab("Library", systemImage: "books.vertical")entries continue to behave as standard destinations, while the activation style applies specifically to the search role declared alongside them.
.tabViewSearchActivation(.searchTabSelection) to a different TabSearchActivation value (or remove the modifier entirely) and observe how selecting the Tab(role: .search) tab activates search differently or falls back to the platform default.Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct TabSearchActivationDemo: View {
var body: some View {
TabView {
Tab("Home", systemImage: "house") {
Text("Home")
.padding()
}
Tab("Library", systemImage: "books.vertical") {
Text("Library")
.padding()
}
Tab(role: .search) {
Text("Search results")
.padding()
}
}
.tabViewSearchActivation(.searchTabSelection)
}
}