Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the more cannot show, when the text is from state #13

Open
shidaying opened this issue Dec 13, 2017 · 25 comments
Open

the more cannot show, when the text is from state #13

shidaying opened this issue Dec 13, 2017 · 25 comments

Comments

@shidaying
Copy link

shidaying commented Dec 13, 2017

// the more cannot show and onReady function is not execute; , this.state.introduction data is from a fetch , I don't know how to fix it,

<ReadMore numberOfLines={2} renderTruncatedFooter={this._renderTruncatedFooter} renderRevealedFooter={this._renderRevealedFooter} onReady={this._handleTextReady}> <Text style={styles.introduce}> // the more cannot show and onReady function is not execute; , this.state.introduction data is from a fetch , I don't know how to fix it, {this.state.introduction} {/*{'wodasdkasdkasbdjabswoaoda我爱的那首搭上打瞌睡大街上大巴见死不救博大精深不对劲啊是djabsdjabsjdbasjdbasjbdjasbjshshhshshshshshhshshhshshshshshsh'}*/} // the more can show </Text> </ReadMore>

@eriveltonelias
Copy link
Contributor

Hi @shilihuan
let me know if you still have some problems with that.

@HarshitMadhav
Copy link

HarshitMadhav commented Feb 11, 2020

Hi @eriveltonelias I faced this same issue today after receiving a string from a fetch I put it in a state and then I passed the state in the readmore component like this

      <ReadMore
             numberOfLines={5}
             renderTruncatedFooter={this._renderTruncatedFooter}
             renderRevealedFooter={this._renderRevealedFooter}
             >
             <Text style={{fontSize:12.5,fontFamily:'Nunito-Regular',color:'#ACAAAA',marginTop:hp(1), width:wp(80), textAlign:'center', marginBottom:hp(1.5)}}>
             {this.state.bio}
           </Text>
           </ReadMore>

It is not displaying read more and read less while I have correctly binded the methods for these in constructor while read more is displaying only when I am passing a hardcoded string like Lorem Ipsum

@eriveltonelias
Copy link
Contributor

Hey @HarshitMadhav

Can you provide a runnable repro on https://snack.expo.io/ ?

@HarshitMadhav
Copy link

HarshitMadhav commented Feb 28, 2020

@eriveltonelias

    getData = () => {
      const url = "some_url";
      fetch(url, {
       method: "POST",
       headers: {
      "Content-Type": "application/json"
       },
       body: JSON.stringify({
         params: "one"
      })
     })
       .then(response => response.json())
      .then(responseJson => {
        this.hideLoading();
      if (responseJson.status == true) {
        this.setState({bio : responseJson.detail.bio})
        GLOBAL.expbio = responseJson.detail.bio;
      } else {
      }
      })
       .catch(error => {
       this.hideLoading();
       console.error(error);
      });
    };


then in render

<ReadMore
             numberOfLines={5}
             renderTruncatedFooter={this._renderTruncatedFooter}
             renderRevealedFooter={this._renderRevealedFooter}
             >
             <Text style={{fontSize:12.5,fontFamily:'Nunito-Regular',color:'#ACAAAA',marginTop:hp(1), 
         width:wp(80), textAlign:'center', marginBottom:hp(1.5)}}>
             {GLOBAL.expbio} **//or this.state.bio both results in read more not showing as the api is 
          called in componentDidMount**
           </Text>
           </ReadMore>

@eriveltonelias
Copy link
Contributor

thanks for providing the repro! I'll investigate.

@eriveltonelias eriveltonelias reopened this Mar 4, 2020
@HarshitMadhav
Copy link

@eriveltonelias Actually the problem is with the first render of component. The first render of read more text component does not show read more text.

@juancsaenz
Copy link

juancsaenz commented Mar 12, 2020

Any solution for that? I'm facing the same problem, when I receive the text from state the show more button is not displaying but if I put hardcoded text it works normally.

@wincjh
Copy link

wincjh commented Apr 21, 2020

+1

@taschik
Copy link

taschik commented May 4, 2020

Hi,

Is there something we can provide that helps fixing this? I ran into the same issue and would love to help fixing the problem. Thanks for looking into this!

@SohailYaseenBhutto
Copy link

Hello,

Actually the problem is that, the component does not re-render itself when text updated. So i have fixed this by creating a method and called it when i have to update text. Like in shouldComponentUpdate of parent. or in callback of any request etc.

updateComponent = async () => {
this.setState({ measured: false, showAllText: false }, async () => {
await nextFrameAsync();
const fullHeight = await measureHeightAsync(this._text);
console.log("fullHeight", fullHeight);
this.setState({ measured: true }, async () => {
await nextFrameAsync();
const limitedHeight = await measureHeightAsync(this._text);
console.log("limitedHeight", limitedHeight);
if (fullHeight > limitedHeight) {
this.setState({ shouldShowReadMore: true }, () => {
this.props.onReady && this.props.onReady();
});
} else {
this.setState({ shouldShowReadMore: false }, () => {
this.props.onReady && this.props.onReady();
});
}
});
});
};

Actually i resets the state first and recalculated the values as in componentDidMount().

@eriveltonelias
Copy link
Contributor

thanks guys! I'll send a fix this weekend.

@HarshitMadhav
Copy link

ALL I did was I did a extra setState() to re render.

@HarshitMadhav
Copy link

@eriveltonelias Thank you for considering this issue.

@SohailYaseenBhutto
Copy link

@eriveltonelias soon please

@taschik
Copy link

taschik commented May 8, 2020

That would be amazing @eriveltonelias ! Thank you for your work.

@taschik
Copy link

taschik commented May 17, 2020

@eriveltonelias did you have the chance to take a look at it? Thank you!

@ikonduktor
Copy link

is it hard to fix it?

@ikonduktor
Copy link

If someone will have this issue, just add some unique key={SOME_ID} from state to rerender component.

@rheng001
Copy link

rheng001 commented Aug 11, 2020

@eriveltonelias
Any update?

@hellozhangran
Copy link

solved it ? @eriveltonelias

@komal1220
Copy link

komal1220 commented Feb 2, 2021

I also face same issue and Fix it by using

in render
let {productDetails} = this.state;
in return part :
{productDetails && productDetails.description &&

<Text style={{textAlign:'justify'}}>
{productDetails && productDetails.description}

}

@sunnyinfydots
Copy link

sunnyinfydots commented Feb 3, 2021

Hello,

I have same issue when i use readmore component with text value which is come from api then it not display see more otherwise as static text it working. Please guide me for solution

@komal1220
Copy link

komal1220 commented Feb 3, 2021

First of all u have to store that text value in state which is come from api then set it as given below.
and in ur render part
let {productDetails} = this.state;
Capture343

@bilalzamank
Copy link

reset array before updating it . like => let responseFromApi=[{ any thing },{ any thing }] don't direct update your state like
setArray(responseFromApi) . before setting array reset it like setArray('') then setArray(responseFromApi)

@hislordshipprof
Copy link

Im using flatlist to render the item from the api but here the show more shows only on the first item any help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests