-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Benjamin
committed
Nov 7, 2023
1 parent
9688f77
commit d9d2fb9
Showing
11 changed files
with
18,843 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,117 @@ | ||
# rn-text-touch-highlight | ||
# React Native Text Highlighter | ||
|
||
rn-text-touch-highlight is a versatile and performant package for highlighting text in React Native | ||
React Native Text Highlighter is a versatile and user-friendly component that allows you to implement text highlighting and selection functionality in your React Native applications. This package simplifies the integration of text selection and annotation features, making it an ideal solution for mobile apps that require text manipulation or document annotation. | ||
|
||
<p align="center"> | ||
<img src="src/assets/example.gif" alt="example" height="300" width="380"/> | ||
</p> | ||
|
||
## Installation | ||
|
||
```sh | ||
To install this package, use npm or yarn: | ||
|
||
```bash | ||
npm install react-native-reanimated | ||
npm install react-native-gesture-handler | ||
npm install rn-text-touch-highlight | ||
``` | ||
|
||
or | ||
|
||
```bash | ||
yarn add react-native-reanimated | ||
yarn add react-native-gesture-handler | ||
yarn add rn-text-touch-highlight | ||
``` | ||
|
||
## Documentation | ||
|
||
The docs can be found here: [https://docs.benjamineruvieru.com/rn-text-touch-highlight](https://docs.benjamineruvieru.com/rn-text-touch-highlight) | ||
|
||
## Usage | ||
|
||
```js | ||
import { multiply } from 'rn-text-touch-highlight'; | ||
Import the `HighlightText` component in your application and include it in your JSX: | ||
|
||
```javascript | ||
import { HighlightText } from 'rn-text-touch-highlight'; | ||
|
||
export default function App() { | ||
const highlightRef: any = React.useRef(); | ||
|
||
// ... | ||
const getHighlightData = () => { | ||
const data = highlightRef.current?.getHighlightedData(); | ||
console.log(data); | ||
}; | ||
const deleteFun = (id) => { | ||
highlightRef.current?.deleteHighlight(id); | ||
}; | ||
|
||
const result = await multiply(3, 7); | ||
return ( | ||
<HighlightText | ||
ref={highlightRef} | ||
clearHighlightOnTap={true} | ||
highlightInitialDelay={500} | ||
initialHighlightData={[ | ||
{ end: 44, start: 20 }, | ||
{ end: 95, start: 70 }, | ||
]} | ||
lineSpace={5} | ||
lineBreakHeight={5} | ||
textColor={'black'} | ||
highlightedTextColor={'white'} | ||
highlightColor={'blue'} | ||
onHighlightStart={() => { | ||
console.log('hightStart'); | ||
}} | ||
onHighlightEnd={(id) => { | ||
console.log('hightEnd', id); | ||
}} | ||
onHighlightTapped={(id, event) => { | ||
console.log('tapped', id, event); | ||
}} | ||
textStyle={{ fontSize: 15 }} | ||
backgroundColor="yellow" | ||
text={'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'} | ||
/> | ||
</View> | ||
); | ||
} | ||
``` | ||
### Props | ||
- `text` (string, required): The text content to display and enable highlighting. | ||
- `textColor` (string): The color of the regular text. | ||
- `highlightedTextColor` (string): The color of the highlighted text. | ||
- `highlightColor` (string): The background color of the highlighted text. | ||
- `lineBreakHeight` (number): The height of line breaks. | ||
- `lineSpace` (number): The space between lines. | ||
- `highlightInitialDelay` (number): Finger press initial delay before highlighting the text. Default is 150 (in milliseconds). | ||
- `onHighlightStart` (function): Callback function when highlighting starts. | ||
- `onHighlightEnd` (function): Callback function when highlighting ends. | ||
- `initialHighlightData` (array of objects): An array specifying the initial highlight data, this is used to render text highlight initially | ||
- `textStyle` (object): Custom styles for the text. | ||
- `marginBottom` (number): Bottom margin for the text container. | ||
- `margin` (number): The margin of the HighlightText component. | ||
- `marginTop` (number): Top margin for the text container. | ||
- `marginLeft` (number): Left margin for the text container. | ||
- `marginRight` (number): Right margin for the text container. | ||
- `onHighlightTapped` (function): Callback function when a highlighted section is tapped. | ||
- `clearHighlightOnTap` (boolean): Clear highlighted sections on tap. | ||
### Ref Functions | ||
- `getHighlightData`: A ref function to retrieve the current highlighting data. | ||
- `deleteHighlight`: A ref function to programmatically delete a highlighted area by its id. | ||
## Example | ||
For a complete example of how to use this package, please refer to the included example app. | ||
## Contributing | ||
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. | ||
## License | ||
MIT | ||
|
||
--- | ||
|
||
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob) | ||
This package is open-source and available under the MIT License. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
module.exports = { | ||
presets: ['module:metro-react-native-babel-preset'], | ||
plugins: ['react-native-reanimated/plugin'], | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ module.exports = function (api) { | |
}, | ||
}, | ||
], | ||
'react-native-reanimated/plugin', | ||
], | ||
}; | ||
}; |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "rn-text-touch-highlight", | ||
"version": "0.1.0", | ||
"description": "rn-text-touch-highlight is a versatile and performant package for highlighting text in React Native", | ||
"description": "React Native Text Highlighter is a versatile and user-friendly component that allows you to implement text highlighting and selection functionality in your React Native applications", | ||
"main": "lib/commonjs/index", | ||
"module": "lib/module/index", | ||
"types": "lib/typescript/src/index.d.ts", | ||
|
@@ -37,15 +37,31 @@ | |
"keywords": [ | ||
"react-native", | ||
"ios", | ||
"android" | ||
"android", | ||
"react", | ||
"highlight", | ||
"text", | ||
"gesture", | ||
"selection", | ||
"interactive", | ||
"reanimated", | ||
"highlighting", | ||
"text-highlighting", | ||
"text-selection", | ||
"text-marker", | ||
"highlighting-library", | ||
"text-highlight", | ||
"UI-component", | ||
"text-manipulation", | ||
"touch-interaction" | ||
], | ||
"repository": "https://github.com/benjamineruvieru/rn-text-touch-highlight", | ||
"author": "Benjamin <[email protected]> (https://www.benjamineruvieru.com)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/benjamineruvieru/rn-text-touch-highlight/issues" | ||
}, | ||
"homepage": "https://github.com/benjamineruvieru/rn-text-touch-highlight#readme", | ||
"homepage": "https://docs.benjamineruvieru.com/rn-text-touch-highlight", | ||
"publishConfig": { | ||
"registry": "https://registry.npmjs.org/" | ||
}, | ||
|
@@ -74,8 +90,10 @@ | |
"@types/react": "17.0.21" | ||
}, | ||
"peerDependencies": { | ||
"react": "*", | ||
"react-native": "*" | ||
"react": ">=18.0.0", | ||
"react-native": ">=0.70.0", | ||
"react-native-gesture-handler": ">=2.10.0", | ||
"react-native-reanimated": ">=2.12.0" | ||
}, | ||
"workspaces": [ | ||
"example" | ||
|
Oops, something went wrong.