|
2 | 2 |
|
3 | 3 | #### Please :star: it, thanks :thumbsup: |
4 | 4 | # react-native-read-more |
5 | | -React native library to show text in a condensed way and expand when needed. Can be used with native or expo on all platforms. |
| 5 | +React native library to show text in a condensed way and expand when needed. Can be used with native or expo on all platforms. Supports TS/JS both. |
6 | 6 |
|
7 | 7 |  |
8 | 8 |
|
@@ -98,25 +98,17 @@ yarn android |
98 | 98 | # Why another library ? |
99 | 99 | This module will calculate where to position `See more` and `See less` within the same paragraph instead of occupying another line. It is a drop-in replacement for `Text` component and you can control when to apply the see more functionality by configuring the `numberOfLines` prop. Moreover, you can also pass your own custom implementation of `Text` component like `ParsedText` ([sample code](https://github.com/fawaz-ahmed/react-native-read-more/issues/37#issuecomment-1047029209)) etc. |
100 | 100 |
|
| 101 | +## Testing with Jest |
| 102 | +Make sure to add `jest.useFakeTimers();` to your test file. |
| 103 | +See [Stackoverflow post](https://stackoverflow.com/questions/50793885/referenceerror-you-are-trying-to-import-a-file-after-the-jest-environment-has) and [jest timer mocks](https://jestjs.io/docs/timer-mocks) |
| 104 | + |
101 | 105 | ## Seeing issues or any feedback or feature suggest ? |
102 | 106 | Create an [issue](https://github.com/fawaz-ahmed/react-native-read-more/issues) with github. |
103 | 107 |
|
104 | 108 | ## Troubleshooting |
105 | 109 | - If you observe `See more` shown always in android, pass prop `allowFontScaling={false}`, refer to this [issue](https://github.com/fawaz-ahmed/react-native-read-more/issues/17) |
106 | 110 | - If you have any nested components other than `Text`, refer to this [issue](https://github.com/fawaz-ahmed/react-native-read-more/issues/52) |
107 | 111 |
|
108 | | -### jest - running unit tests |
109 | | -This package is not transpiled. So inorder for your test cases to work, this package should be transpiled by babel. For this you need to add this path `!node_modules/@fawazahmed/react-native-read-more/` under `transformIgnorePatterns` option provided by `jest`. In your `package.json` you will see this `jest` config: |
110 | | -``` |
111 | | -"jest": { |
112 | | - "preset": "react-native", |
113 | | - "transformIgnorePatterns": [ |
114 | | - "!node_modules/@fawazahmed/react-native-read-more/" // add this line |
115 | | - ] |
116 | | -} |
117 | | -``` |
118 | | -refer to jest docs [here](https://jestjs.io/docs/en/tutorial-react-native#transformignorepatterns-customization) and github [issue](https://github.com/fawaz-ahmed/react-native-read-more/issues/19) |
119 | | - |
120 | 112 | ### Known issues |
121 | 113 | `Android only` if `numberOfLines` with a value of `1` is passed down as a prop, text in android devices will overlap at the end of line. This is an issue in `react-native` where text from other lines concatenates into the first one even if we add `\n` to the first line, where the lines returned from `onTextLayout` indicates a different response. |
122 | 114 | To overcome this issue, use `numberOfLines` greater than `1`. |
0 commit comments