Skip to content

Commit e23eac2

Browse files
authored
Issue 78: pass information whether can be expanded or not in on ready… (#81)
* Issue 78: pass information whether can be expanded or not in on ready callback, update example too * Issue 78: revert number fo lines back to default value which is 3
1 parent 0cd854b commit e23eac2

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export default Home;
7676
| `expandOnly` | `bool` | no | defaults to `false` => hide see less option similar to a linkedIn post
7777
| `onExpand` | `func` | no | optional callback executed when expanded
7878
| `onCollapse` | `func` | no | optional callback executed when collapsed
79-
| `onReady` | `func` | no | optional callback executed when see more placement measurements are completed
79+
| `onReady` | `func` | no | optional callback executed when see more placement measurements are completed, this function will pass 2 arguments `({ canExpand, expandedLinesCount })`, where `canExpand` is a boolean specifying if text can be expanded and `expandedLinesCount` is a number indicating the number of lines when text is in expanded state.
8080
| `collapsed` | `bool` | no | Control collapsed state programatically see [issue](https://github.com/fawaz-ahmed/react-native-read-more/issues/61)
8181
| `debug` | `bool` | no | print debug logs to examine
8282
| `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)

example/App.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
import React, {useState} from 'react';
1+
import React from 'react';
22
import {SafeAreaView, StyleSheet, View} from 'react-native';
33
import ReadMore from './src';
44

55
const App = () => {
6+
const onReady = ({canExpand, expandedLinesCount}) => {
7+
// console.log('on ready', {canExpand, expandedLinesCount});
8+
};
69
return (
710
<SafeAreaView style={styles.safe}>
811
<View style={styles.root}>
9-
<ReadMore numberOfLines={3} style={styles.textStyle}>
12+
<ReadMore numberOfLines={3} style={styles.textStyle} onReady={onReady}>
1013
{
1114
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
1215
}

example/src/ReadMore.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ const ReadMore = ({
471471

472472
if (!_seeMore) {
473473
log('no measurement is needed');
474-
onReady();
474+
onReady({canExpand: _seeMore, expandedLinesCount: lines.length});
475475
}
476476
// eslint-disable-next-line react-hooks/exhaustive-deps
477477
}, [numberOfLines, lines]);
@@ -581,7 +581,7 @@ const ReadMore = ({
581581

582582
const handle = setTimeout(() => {
583583
setIsReady(true);
584-
onReady();
584+
onReady({canExpand: seeMore, expandedLinesCount: lines.length});
585585
}, debounceSeeMoreCalc);
586586
return () => clearTimeout(handle);
587587
// eslint-disable-next-line react-hooks/exhaustive-deps

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface ReadMoreProps extends TextProps {
1515
expandOnly?: boolean;
1616
seeMoreOverlapCount?: number;
1717
debounceSeeMoreCalc?: number;
18-
onReady?: () => void;
18+
onReady?: ({ canExpand: boolean, expandedLinesCount: number }) => void;
1919
seeMoreContainerStyleSecondary?: StyleProp<ViewStyle>;
2020
onSeeMore?: () => void;
2121
onSeeLess?: () => void;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fawazahmed/react-native-read-more",
3-
"version": "3.0.2",
3+
"version": "3.0.3",
44
"description": "A simple react native library to show large blocks of text in a condensed manner with the ability to collapse and expand.",
55
"main": "dist/index.js",
66
"types": "index.d.ts",

0 commit comments

Comments
 (0)