0.1.0 • Published 1 year ago

react-native-live-text-view v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

react-native-live-text-view

Enabling Live Text interactions with image.

Highlights

  • 🔥 Built with Expo's Module API
  • 🎉 Supports both Image and expo-image.
  • 🍎 iOS only (iOS 16.0+)

Preview

preview

Installation

Expo development build

Install the library:

npx expo install react-native-live-text-view

Then rebuild your app:

npx expo prebuild -p ios --clean npx expo run:ios

Bare React Native projects

You must ensure that you have installed and configured the expo package before continuing.

Install the library:

npm install react-native-live-text-view

Run npx pod-install

Usage

Basic

import { LiveTextView } from 'react-native-live-text-view';

<LiveTextView>
  <Image source={{ uri: imageUri }} style={{ height, width }} />
</LiveTextView>;

Example

git clone repo
cd example
npm run ios

API

Props

NameTypeRequiredDescription
childrenReactNodeYesThe image for live text interaction.
styleStyleProp<ViewStyle>NoContainer style
disabledbooleanNoWhether to turn off the image analysis. Default value is false
liveActionButtonHiddenbooleanNoWhether to hide the live action button in the lower right corner. Default value is false
onStart() => voidNoCalled when image analysis starts.
onReady(event: OnReadyEventData) => voidNoCalled when image analysis success.
onError(event: OnErrorEventData) => void;NoCalled when image analysis fail.
onHighlightChange(isHighlight: boolean) => voidNoCalled when recognized items in the image appear highlighted as a result of a person tapping the Live Text button.
onTextSelectionChange(event: OnTextSelectionChangeEventData) => voidNoCalled when the interaction’s text selection changes.

Types

interface OnReadyEventData {
  /*
   * Whether the analysis finds the specified types in the image.
   */
  hasResults: boolean;
  /*
   * The string that the text items in the image represent.
   */
  transcript: string;
}
interface OnErrorEventData {
  /*
   * error message
   */
  error: string;
}
interface OnTextSelectionChangeEventData {
  /*
   * Selected text, require iOS 17.0+
   */
  selectedText: string;
  /*
   * Whether has text been selected.
   */
  hasActiveTextSelection: boolean;
}
interface OnHighlightChangeEventData {
  /*
   * Whether recognized items in the image appear highlighted
   */
  isHighlight: boolean;
}