fawaz-ahmed / react-native-read-more

React native library to show text in a condensed way and expand when needed. Drop in replacement for Text component and highly customizable. Can be used with expo or native cli for react native.
https://www.npmjs.com/package/@fawazahmed/react-native-read-more
MIT License
274 stars 37 forks source link

add a prop to know nbOfLines so we can disable or not controlled collapse #78

Closed pierroo closed 1 year ago

pierroo commented 1 year ago

I am using the controlled collapse, so that when the user taps on the entire parent view it expand the contained text. But as of now there is no way to know whether or not there is any need to expand (ie nbOfLines > the number we set as props), which leads to a useless tap to expand. (in my case it triggers other functions, like adjusting the css top etc; so I really don't want to have it triggered when not needed)

Let me know if unclear :)

EDIT: and while at it, anyway to also return the "size" (width and height) of the collapsed text? I guess you compute it somehow to adjust the animated height and width upon expanding? This size would help me to "place" (top / bottom etc) the actually expanding text.

fawaz-ahmed commented 1 year ago

Thanks for bringing this up @pierroo , would it be fine if onReady callback passes this information in arguments ?

pierroo commented 1 year ago

Absolutely, that's exactly where I was hoping to get those information from. Thank you!

fawaz-ahmed commented 1 year ago

Hi @pierroo , I've manged to add params to onReady callback ({ canExpand, expandedLinesCount }). As for the size, the text component will fill the parent component width and the height can be proportional to expandedLinesCount * font size. Hope this helps. Upgrade to ver 3.0.3 to see the changes