Skip to content

Add searchable — a navigation search field - #48

Merged
colemancda merged 6 commits into
masterfrom
feature/searchable
Jul 23, 2026
Merged

Add searchable — a navigation search field#48
colemancda merged 6 commits into
masterfrom
feature/searchable

Conversation

@colemancda

Copy link
Copy Markdown
Member

Adds .searchable(text:prompt:), which attaches a search field to the enclosing navigation stack bound to a String. The developer filters their own content off the bound text — the standard SwiftUI idiom.

Mechanism

Follows the exact pattern navigationTitle already uses: the modifier is a _ResolutionEffectView that records its field into the per-screen TitleSink (current text, a registered string callback, prompt). NavigationStack._render collects each screen's descriptor into a parallel searches prop, and the interpreter renders an OutlinedTextField (search icon + prompt) above that screen's content.

Text round-trips with the same uncontrolled-with-reconciliation scheme as TextField — Compose owns the cursor, lastSent suppresses the echo — keyed by the stable screen index rather than the callback id (which churns every evaluation).

Verification

  • swift test — new emission/round-trip test (asserts the root screen's descriptor carries text + prompt, and that string input drives the binding), 69 total passing
  • Emulator (new "Searchable" catalog screen, a fruit list): the field surfaced under the nav title with a search icon and "Search fruit" prompt; typing a narrowed the list to the eight fruits containing 'a', and adding p (→ ap) narrowed it live to Apple / Apricot / Grape, with the text accumulating and the cursor preserved across each round-trip

Scope

Like alert/sheet, the field is picked up per navigation screen; searchable outside a NavigationStack is a no-op (no title sink), matching how navigationTitle behaves. Search scopes and isSearching are not included.

@colemancda
colemancda merged commit ebbcaae into master Jul 23, 2026
6 checks passed
@colemancda
colemancda deleted the feature/searchable branch July 23, 2026 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant