0.0.15 • Published 2 years ago

@jurishandapp/react-native-selectable-text v0.0.15

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

react-native-selectable-text

This project came up to try to get around the lack of libraries related to text selection in React Native. If you support the project, feel free to interact and help improve the library.

Now available for IOS

Installation

npm install @jurishandapp/react-native-selectable-text --save
yarn add @jurishandapp/react-native-selectable-text

Linking

If the project has an error, run the following command

react-native link @jurishandapp/react-native-selectable-text

Manual Installation

Android

  1. Open up android/app/src/main/java/[...]/MainApplication.java
  • Add import com.reactnativeselectabletext.SelectableTextPackage; to the imports at the top of the file
  1. Append the following lines to android/settings.gradle:
     include ':@jurishandapp_react-native-selectable-text'
     project(':@jurishandapp_react-native-selectable-text').projectDir = new File(rootProject.projectDir, 
     '../node_modules/@jurishandapp/react-native-selectable-text/android')

iOS - Binary Linking (Alternative 1)

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modules@jurishandapp/react-native-selectable-text and add RNSelectableText.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNSelectableText.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<

iOS - Pods (Alternative 2)

  1. Add pod 'RNSelectableText', :path => '../node_modules/@jurishandapp/react-native-selectable-text/ios/RNSelectableText.podspec' to your projects podfile
  2. run pod install

Usage

import { SelectableText } from "@jurishandapp/react-native-selectable-text";

// Use normally, it is a drop-in replacement for react-native/Text
<SelectableText
  menuItems={["Custom 1", "Custom 1"]}
  /* 
    Called when the user taps in a item of the selection menu:
    - eventType: (string) is the label
    - content: (string) the selected text portion
    - selectionStart: (int) is the start position of the selected text
    - selectionEnd: (int) is the end position of the selected text
   */
  onSelection={({ eventType, content, selectionStart, selectionEnd }) => {}}
  value="Text example"
/>;

Props

namedescriptiontypedefault
valuetext contentstring""
onSelectionCalled when the user taps in a item of the selection menu({ eventType: string, content: string, selectionStart: int, selectionEnd: int }) => void() => {}
onCreateSelectionCalled when user initiates selection({ content: string, selectionStart: int, selectionEnd: int }) => void() => {}
onChangeSelectionCalled when user moves selection({ content: string, selectionStart: int, selectionEnd: int }) => void() => {}
onDestroySelectionCalled when the selection is closed({ content: string, selectionStart: int, selectionEnd: int }) => void() => {}
menuItemscontext menu itemsarray(string)[]
styleadditional styles to be applied to textObjectnull
highlightsarray of text ranges that should be highlighted with an optional idarray({ id: string, start: int, end: int })[]
highlightColorhighlight colorstringnull
onHighlightPresscalled when the user taps the highlight(id: string) => void() => {}
enabledContextMenuenable context menubooleantrue
appendToChildrenelement to be added in the last line of textReactNodenull
TextComponentText component used to render valueReactNode
textValueProptext value prop for TextComponent. Should be used when passing TextComponent. Defaults to 'children' which works for string'children'
textComponentPropsadditional props to pass to TextComponentobjectnull

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

0.0.15

2 years ago

0.0.10

2 years ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.14

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.10.0

2 years ago

0.9.0

2 years ago

0.8.0

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago