Places: Apple's suggestions while typing, chosen with one tap - #287
Conversation
Adding a place and saying where a meetup is now show Apple Maps' suggestions for the words so far, before Return, as Apple Maps does: places, and for a meetup street addresses, with the words as typed still offered as the address. They come from MKLocalSearchCompleter, which is made for it, one completer per kind so each suggestion's kind is known; the words are asked about once they rest for 0.15 s, and an answer for older words never shows over newer ones. A suggestion chosen is searched for by its name and address, and what that finds is chosen: the place with its identifier, marked when it is on PetNote already, or the address as Apple writes it. A place the search no longer finds searches for its name instead. Return still searches as before. The meetup form scrolls its search field to the top when suggestions arrive, so they show above the keyboard. The stand-in directory now matches a place by its address as well as its name, as a suggestion's search needs, and a stand-in suggester answers in the emulator build. The device probe gains a check of the completer on a real iPhone; it was not run this time. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7ca914fbc7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let pause = typingPause | ||
| typing = Task { [weak self] in | ||
| if pause > .zero { try? await Task.sleep(for: pause) } | ||
| guard !Task.isCancelled, let self else { return } | ||
| let found = await self.suggester.suggestions(for: text, addresses: self.findsAddresses) |
There was a problem hiding this comment.
Clear suggestions as soon as the input changes
When suggestions for one fragment are already visible and the user continues typing, this branch retains those rows throughout the 150 ms pause and the subsequent MapKit request. During that potentially long interval the rows no longer correspond to the text field, and tapping one can select the previous place or address; it also prevents the meetup's empty-to-nonempty scroll trigger from firing for the replacement list. Clear the existing suggestions before scheduling the request for the new fragment.
Useful? React with 👍 / 👎.
| waiting.removeValue(forKey: key)?.resume(returning: []) | ||
| // The same words again: the completer does not answer twice. | ||
| if completer.queryFragment == text { return suggestions(from: completer) } | ||
| return await withCheckedContinuation { continuation in |
There was a problem hiding this comment.
Keep waiting when an identical fragment is still in flight
If a second request for the same normalized fragment arrives before the first completer callback—for example after adding trailing whitespace or quickly deleting and retyping characters—this removes the only continuation and immediately reads completer.results, which may still be empty or belong to the preceding query. The eventual callback then has no waiter, so the correct suggestions are discarded and the UI stays empty or stale until the text changes again. The same-fragment path needs to distinguish cached completed results from an in-flight request and keep a continuation for the latter.
Useful? React with 👍 / 👎.
Follows #286. Adding a place, and saying where a meetup is, now show Apple Maps' suggestions for the words typed so far, before Return, as Apple Maps does.
What shows
Where they come from
MKLocalSearchCompleter, which Apple made for this; a search on every key could be throttled.Core/Maps/PlaceSuggestions.swift,MapKitPlaceSuggester).Choosing one (
ApplePlaceFinder.choose(_:))Also
StandInPlaceSuggesteranswers in the emulator build.AppleMapsDeviceProbeTestsgains a check of the real completer and of finding a suggested place. It runs on a real iPhone only, and was not run this time.Tests
PlaceSuggestionsTests(10):testSuggestionsWhileTypingChooseAPlaceOrAnAddressis new.PlacesMeetupsUITestsandCheckinHistoryUITestspassed (22, 0 failed). The tests that touch the search field ran again after the scroll change (6 passed).Screenshots:
ios-native/docs/visual-parity/place-suggestions.jpg.🤖 Generated with Claude Code