Reputation: 443
How can I get the number of lines of Text component in React Native?
I want to show "Read more button" if the number of lines of text component is over 4.
Is there any props to get the number of lines?
I already know there is a numberOfLines props in Text Component but it's just about setting the number of lines. Am I right?
Upvotes: 2
Views: 2872
Reputation: 4252
from onContentSizeChange props of textinput you will get height and then divide the height to get number of lines
onContentSizeChange={e =>
console.log(e.nativeEvent.contentSize.height)
}
for more check documentation
Upvotes: 0
Reputation: 2200
In current version this feature is not available in RN, But there is the best library you can use react-native-read-more-text which will give results as you want.
Upvotes: 2