From aa286885d7002b807079a058a5231c36fd9eb9a8 Mon Sep 17 00:00:00 2001 From: Alex Buimistriuc Date: Mon, 15 Jan 2018 16:33:13 +0200 Subject: [PATCH 1/8] adding expanded property --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index ad7a9cd..58ffccf 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,7 @@ export default class ReadMore extends React.Component { state = { measured: false, shouldShowReadMore: false, - showAllText: false, + showAllText: this.props.expanded ? true : false, } async componentDidMount() { From 2079de650e5baa3e60095dcd443ba748bb39562d Mon Sep 17 00:00:00 2001 From: Alex Buimistriuc Date: Mon, 15 Jan 2018 17:00:06 +0200 Subject: [PATCH 2/8] adding defaultProps --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 58ffccf..6b9238a 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,11 @@ export default class ReadMore extends React.Component { state = { measured: false, shouldShowReadMore: false, - showAllText: this.props.expanded ? true : false, + showAllText: this.props.expanded, + } + + static defaultProps = { + expanded: false } async componentDidMount() { From fd0db4bda16176bb6f606c1b71cc0dad1f2f9288 Mon Sep 17 00:00:00 2001 From: Alex Buimistriuc Date: Mon, 15 Jan 2018 17:15:07 +0200 Subject: [PATCH 3/8] move defaultProps to the top of the class --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 6b9238a..392f334 100644 --- a/index.js +++ b/index.js @@ -6,16 +6,16 @@ import { } from 'react-native'; export default class ReadMore extends React.Component { + static defaultProps = { + expanded: false + } + state = { measured: false, shouldShowReadMore: false, showAllText: this.props.expanded, } - static defaultProps = { - expanded: false - } - async componentDidMount() { await nextFrameAsync(); From d8478f9a37fc78e8f1678ccd2a19e2a0b8b15c7c Mon Sep 17 00:00:00 2001 From: Alex Buimistriuc Date: Tue, 16 Jan 2018 09:57:16 +0200 Subject: [PATCH 4/8] fix expanded prop feature --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 392f334..3670341 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,7 @@ export default class ReadMore extends React.Component { state = { measured: false, shouldShowReadMore: false, - showAllText: this.props.expanded, + showAllText: false, } async componentDidMount() { @@ -30,6 +30,10 @@ export default class ReadMore extends React.Component { if (fullHeight > limitedHeight) { this.setState({shouldShowReadMore: true}, () => { this.props.onReady && this.props.onReady(); + + if (this.props.expanded) { + this._handlePressReadMore() + } }); } } From 29ef6d9cfcf441392568af4e076ecf9e772ba74b Mon Sep 17 00:00:00 2001 From: Alex Buimistriuc Date: Tue, 16 Jan 2018 10:12:11 +0200 Subject: [PATCH 5/8] hide text until measured --- index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.js b/index.js index 3670341..5a9d429 100644 --- a/index.js +++ b/index.js @@ -36,6 +36,8 @@ export default class ReadMore extends React.Component { } }); } + + this._text.style = {opacity: 0} } render() { @@ -54,6 +56,7 @@ export default class ReadMore extends React.Component { numberOfLines={measured && !showAllText ? numberOfLines : 0} ref={text => { this._text = text; }}> {this.props.children} + style={{opacity: 0}} {this._maybeRenderReadMore()} From bbcaff0fc55a9a0be08135a292015fcbfed57b0c Mon Sep 17 00:00:00 2001 From: Alex Buimistriuc Date: Tue, 16 Jan 2018 10:13:39 +0200 Subject: [PATCH 6/8] fix --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 5a9d429..fa88c53 100644 --- a/index.js +++ b/index.js @@ -54,9 +54,9 @@ export default class ReadMore extends React.Component { { this._text = text; }}> + ref={text => { this._text = text; }} + style={{opacity: 0}}> {this.props.children} - style={{opacity: 0}} {this._maybeRenderReadMore()} From 5eb7f42cf1733b3a8c10378c7e84ca073c488748 Mon Sep 17 00:00:00 2001 From: Alex Buimistriuc Date: Tue, 16 Jan 2018 10:14:49 +0200 Subject: [PATCH 7/8] fix --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index fa88c53..d970ed9 100644 --- a/index.js +++ b/index.js @@ -37,7 +37,7 @@ export default class ReadMore extends React.Component { }); } - this._text.style = {opacity: 0} + this._text.style = {opacity: 1} } render() { From dea95391edebb226b472cc5da23054a894992cf1 Mon Sep 17 00:00:00 2001 From: Alex Buimistriuc Date: Tue, 16 Jan 2018 10:20:03 +0200 Subject: [PATCH 8/8] fix --- index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/index.js b/index.js index d970ed9..474a7f3 100644 --- a/index.js +++ b/index.js @@ -36,8 +36,6 @@ export default class ReadMore extends React.Component { } }); } - - this._text.style = {opacity: 1} } render() { @@ -55,7 +53,7 @@ export default class ReadMore extends React.Component { { this._text = text; }} - style={{opacity: 0}}> + style={{opacity: this.state.measured ? 1 : 0}}> {this.props.children}