Add searchable — a navigation search field - #48
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
.searchable(text:prompt:), which attaches a search field to the enclosing navigation stack bound to aString. The developer filters their own content off the bound text — the standard SwiftUI idiom.Mechanism
Follows the exact pattern
navigationTitlealready uses: the modifier is a_ResolutionEffectViewthat records its field into the per-screenTitleSink(current text, a registered string callback, prompt).NavigationStack._rendercollects each screen's descriptor into a parallelsearchesprop, and the interpreter renders anOutlinedTextField(search icon + prompt) above that screen's content.Text round-trips with the same uncontrolled-with-reconciliation scheme as
TextField— Compose owns the cursor,lastSentsuppresses 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 passinganarrowed the list to the eight fruits containing 'a', and addingp(→ap) narrowed it live to Apple / Apricot / Grape, with the text accumulating and the cursor preserved across each round-tripScope
Like
alert/sheet, the field is picked up per navigation screen;searchableoutside aNavigationStackis a no-op (no title sink), matching hownavigationTitlebehaves. Search scopes andisSearchingare not included.