feat: add useDetectedEntities reactive (as-you-type) hook#8
Merged
Conversation
Adds a reactive, debounced detection hook for a changing string — ideal for
as-you-type input. Pass text, get { entities, isDetecting, status, error };
cancellation-safe (latest text wins), skips empty input, manages model readiness
internally.
Factors the model-readiness/auto-prepare logic out of useDataDetector into a shared
internal useModelLifecycle hook, used by both public hooks. useDataDetector's public
API is unchanged.
Version bump and changelog cut left for release time.
…ve useDataDetector) Adds a Detection Mode toggle so the example demonstrates the full API: as-you-type detection via useDetectedEntities, on-tap detection via useDataDetector, plus model status and language selection. Validated on Android: both modes detect correctly.
- Detected entities now render in a horizontal strip ABOVE the input, so they stay visible while typing (KeyboardAvoidingView keeps input + results above the keyboard). - Mode (Live/On tap) is a compact pill toggle; language is a bottom-sheet dropdown (all 15 models). Dropped the entity-type filter. - Refined dark theme. Validated on Android: live detection updates above the keyboard while typing.
- Horizontal entity strip now spans edge-to-edge (negative margin cancels the body padding) with the padding re-applied inside the scroll content, so chips scroll to the screen edge while the first/last stay aligned with the UI. - More bottom padding so the input clears the Android gesture bar when the keyboard is closed.
…ntext - Reorganize the example into focused components (components/), with shared theme.ts and constants.ts; App.tsx is now just composition + the two hooks. - Replace the deprecated react-native SafeAreaView with SafeAreaProvider + useSafeAreaInsets (real device insets), removing the deprecation warning. Verified on Android: renders correctly with safe-area insets, live + on-tap detection both work.
Group state declarations, derive typesKey inline, and read types directly in the detection effect. No behavior change (typesKey still gates re-runs; latest run wins).
- Upgrade example to Expo SDK 56 (react-native 0.85.3, react 19.2.3, react-native-safe-area-context 5.7.0) — aligns with the repo root's RN line and adds iOS 26 support, fixing the simulator runtime errors. - Extract the screen into screens/DataDetector.tsx; App.tsx is a thin wrapper. - Component style/formatting cleanups.
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.
What
Adds
useDetectedEntities(text, options?)— the reactive counterpart touseDataDetector. You pass a (changing) string and get back the detected entities, recomputed as the text changes. Built for as-you-type input.{ entities, isDetecting, status, error }.debounceMs, default 300) and cancellation-safe — only the latest text's result commits (last-write-wins via a monotonic run id), so fast typing never shows a stale result.enabled: falsepauses and keeps the last result.debounceMs,types,language,enabled,autoPrepare.Design
Two hooks, by intent:
useDataDetector— imperative (detectyou call yourself; e.g. per chat message).useDetectedEntities— reactive (feed a string, get entities; as-you-type).Shared logic (model status + auto-prepare) is factored into an internal
useModelLifecyclehook used by both.useDataDetector's public API is unchanged.Notes
[Unreleased]per the release workflow.detect()/getModelStatus();build(typecheck) +lintpass. Not yet exercised in the example app on-device.