@fawazahmed/react-native-read-more
Advanced tools
Comparing version 1.1.4 to 1.1.5
@@ -18,2 +18,8 @@ import React, {memo, useState, useEffect, useCallback} from 'react'; | ||
const readmoreAnimation = LayoutAnimation.create( | ||
300, | ||
LayoutAnimation.Types.easeInEaseOut, | ||
LayoutAnimation.Properties.opacity, | ||
); | ||
const ReadMore = ({ | ||
@@ -33,2 +39,5 @@ numberOfLines, | ||
allowFontScaling, | ||
onExpand, | ||
onCollapse, | ||
expandOnly, | ||
...restProps | ||
@@ -85,12 +94,3 @@ }) => { | ||
setCollapsed((prev) => !prev); | ||
if (animate) { | ||
LayoutAnimation.configureNext( | ||
LayoutAnimation.create( | ||
300, | ||
LayoutAnimation.Types.linear, | ||
LayoutAnimation.Properties.opacity, | ||
), | ||
); | ||
} | ||
}, [setCollapsed, animate]); | ||
}, [setCollapsed]); | ||
@@ -106,3 +106,14 @@ useEffect(() => { | ||
useEffect(() => { | ||
if (collapsed === afterCollapsed) { | ||
return; | ||
} | ||
const callback = collapsed ? onCollapse : onExpand; | ||
setAfterCollapsed(collapsed); | ||
if (animate) { | ||
LayoutAnimation.configureNext(readmoreAnimation, callback); | ||
} else { | ||
callback(); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [collapsed]); | ||
@@ -126,3 +137,3 @@ | ||
const textProps = collapsed | ||
const textProps = afterCollapsed | ||
? { | ||
@@ -174,3 +185,3 @@ onLayout: onTextLayout, | ||
{children || ''} | ||
{seeMore && !collapsed && ( | ||
{seeMore && !collapsed && !expandOnly && ( | ||
<TextComponent | ||
@@ -250,2 +261,5 @@ {...additionalProps} | ||
allowFontScaling: PropTypes.bool, | ||
onExpand: PropTypes.func, | ||
onCollapse: PropTypes.func, | ||
expandOnly: PropTypes.bool, | ||
}; | ||
@@ -266,4 +280,7 @@ | ||
ellipsis: '...', | ||
onExpand: () => {}, | ||
onCollapse: () => {}, | ||
expandOnly: false, | ||
}; | ||
export default memo(ReadMore); |
{ | ||
"name": "@fawazahmed/react-native-read-more", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"description": "A simple react native library to show large blocks of text in a condensed manner with the ability to collapse and expand.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -75,2 +75,5 @@ ![NPM Downloads](https://img.shields.io/npm/dw/@fawazahmed/react-native-read-more) ![NPM License](https://img.shields.io/npm/l/@fawazahmed/react-native-read-more) ![NPM Version](https://img.shields.io/npm/v/@fawazahmed/react-native-read-more) | ||
| `customTextComponent` | `React component` | no | defaults to `Text` | ||
| `expandOnly` | `bool` | no | defaults to `false` => hide see less option similar to a linkedIn post | ||
| `onExpand` | `func` | no | optional callback executed when expanded | ||
| `onCollapse` | `func` | no | optional callback executed when collapsed | ||
@@ -100,1 +103,13 @@ Any additional props are passed down to underlying `Text` component. | ||
- 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) | ||
### jest - running unit tests | ||
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: | ||
``` | ||
"jest": { | ||
"preset": "react-native", | ||
"transformIgnorePatterns": [ | ||
"!node_modules/@fawazahmed/react-native-read-more/" // add this line | ||
] | ||
} | ||
``` | ||
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) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
493308
384
114