Text - numberOfLines not working
See original GitHub issueDescription
I have used Text component with numberOfLines and ellipsizeMode properties. I have even tried this here : https://facebook.github.io/react-native/docs/text.html . I have tried editing it on the fly. But numberOfLines works only with value = {1} and not with any other numbers. Please advise if I am missing anything here.
My requirement is to show max 3 lines of text and then truncate it with ellipsizeMode to tail. Any working example would be appreciated.
Code
`import React, { Component } from ‘react’; import { AppRegistry, Text, StyleSheet } from ‘react-native’;
class TextInANest extends Component { constructor(props) { super(props); this.state = { titleText: “Bird’s Nest”, bodyText: ‘This is not really a bird nest. Adding long text to see if it truncates after 3 lines and displays the truncation sign properly.’ }; }
render() {
return (
<Text style={styles.baseText}>
<Text style={styles.titleText} onPress={this.onPressTitle}>
{this.state.titleText}
</Text>
<Text numberOfLines={3} ellipsizeMode ={‘tail’}>
{this.state.bodyText}
</Text>
</Text>
);
}
}
const styles = StyleSheet.create({ baseText: { fontFamily: ‘Cochin’, }, titleText: { fontSize: 20, fontWeight: ‘bold’, }, });
// App registration and rendering AppRegistry.registerComponent(‘TextInANest’, () => TextInANest);`
Additional Information
- React Native version: 0.35
- Platform: both
- Operating System: Mac OS
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
This still does not work for me either. Very basic un-nested
<Text numberOfLines={1}>
… Even tried setting width.@reneweb I am still not able to find the solution. It’s not even working with the editable examples given here. https://facebook.github.io/react-native/docs/text.html Any reason why those examples are not working when set with numberOfLines>1. ?
Thanks.