Skip to content

feat: add useDetectedEntities reactive (as-you-type) hook#8

Merged
pablogdcr merged 7 commits into
mainfrom
feat/as-you-type-hook
Jun 6, 2026
Merged

feat: add useDetectedEntities reactive (as-you-type) hook#8
pablogdcr merged 7 commits into
mainfrom
feat/as-you-type-hook

Conversation

@pablogdcr

Copy link
Copy Markdown
Owner

What

Adds useDetectedEntities(text, options?) — the reactive counterpart to useDataDetector. You pass a (changing) string and get back the detected entities, recomputed as the text changes. Built for as-you-type input.

const { entities, isDetecting } = useDetectedEntities(text, { debounceMs: 250 });
  • Returns { entities, isDetecting, status, error }.
  • Debounced (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.
  • Skips empty input; enabled: false pauses and keeps the last result.
  • Manages model readiness internally (auto-downloads on Android, no-op on iOS).
  • Options: debounceMs, types, language, enabled, autoPrepare.

Design

Two hooks, by intent:

  • useDataDetectorimperative (detect you call yourself; e.g. per chat message).
  • useDetectedEntitiesreactive (feed a string, get entities; as-you-type).

Shared logic (model status + auto-prepare) is factored into an internal useModelLifecycle hook used by both. useDataDetector's public API is unchanged.

Notes

  • No version bump / changelog cut — entries under [Unreleased] per the release workflow.
  • Pure-JS over the already-validated native detect() / getModelStatus(); build (typecheck) + lint pass. Not yet exercised in the example app on-device.

pablogdcr added 7 commits June 6, 2026 13:49
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.
@pablogdcr pablogdcr merged commit 25f8610 into main Jun 6, 2026
4 checks passed
@pablogdcr pablogdcr deleted the feat/as-you-type-hook branch June 6, 2026 13:39
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