Skip to content

Commit

Permalink
Fix Issue 63: custom function when See More pressed (#64)
Browse files Browse the repository at this point in the history
* feat: + onSeeMoreBlocked prop

* fix: README styling

Co-authored-by: Christopher Fields II <christopherfieldsii@gamestop.com>
  • Loading branch information
ChrisLFieldsII and Christopher Fields II authored Apr 23, 2022
1 parent 3d8e2f4 commit 2cedb43
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export default Home;
| `onCollapse` | `func` | no | optional callback executed when collapsed
| `onReady` | `func` | no | optional callback executed when see more placement measurements are completed
| `seeMoreContainerStyleSecondary` | `object` | no | Incase of text overlap, pass { position: 'relative' } see [issue](https://github.com/fawaz-ahmed/react-native-read-more/issues/52) (not recommended)
| `onSeeMoreBlocked` | `func` | no | when a function is passed, will disable the default See More toggling and use the custom callback instead. Useful to do things like open a modal instead of expanding text when See More is pressed.

Any additional props are passed down to underlying `Text` component.

Expand Down
12 changes: 10 additions & 2 deletions example/src/ReadMore.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const ReadMore = ({
debounceSeeMoreCalc,
onReady,
seeMoreContainerStyleSecondary,
onSeeMoreBlocked,
...restProps
}) => {
const [additionalProps, setAdditionalProps] = useState({});
Expand Down Expand Up @@ -180,8 +181,13 @@ const ReadMore = ({
);

const toggle = useCallback(() => {
setCollapsed(prev => !prev);
}, [setCollapsed]);
if (onSeeMoreBlocked) {
onSeeMoreBlocked();
}
else {
setCollapsed(prev => !prev);
}
}, [setCollapsed, onSeeMoreBlocked]);

const updateLineOfImpact = useCallback(
(_text = '', resetCollapsedChildren = true) => {
Expand Down Expand Up @@ -692,6 +698,7 @@ ReadMore.propTypes = {
debounceSeeMoreCalc: PropTypes.number,
onReady: PropTypes.func,
seeMoreContainerStyleSecondary: PropTypes.object,
onSeeMoreBlocked: PropTypes.func,
};

ReadMore.defaultProps = {
Expand All @@ -716,6 +723,7 @@ ReadMore.defaultProps = {
}),
onReady: () => {},
seeMoreContainerStyleSecondary: {},
onSeeMoreBlocked: undefined,
};

export default memo(ReadMore);
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface ReadMoreProps extends TextProps {
debounceSeeMoreCalc?: number;
onReady?: () => void;
seeMoreContainerStyleSecondary?: StyleProp<ViewStyle>;
onSeeMoreBlocked?: () => void;
}
declare const ReadMore: React.FC<ReadMoreProps>;
export default ReadMore;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fawazahmed/react-native-read-more",
"version": "2.3.5",
"version": "2.3.6",
"description": "A simple react native library to show large blocks of text in a condensed manner with the ability to collapse and expand.",
"main": "dist/index.js",
"types": "index.d.ts",
Expand Down

0 comments on commit 2cedb43

Please sign in to comment.