I'm having a long text in my app and I need to truncate it and add three dots to the end.
How can I do that in React Native Text element?
Thanks
numberOfLines
parameter on a Text
component:<Text numberOfLines={1}>long long long long text<Text>
Will produce:
long long long…
(Assuming you have short width container.)
ellipsizeMode
parameter to move the ellipsis to the head
or middle
. tail
is the default value.<Text numberOfLines={1} ellipsizeMode='head'>long long long long text<Text>
Will produce:
…long long text
NOTE: The Text
component should also include style={{ flex: 1 }}
when the ellipsis needs to be applied relative to the size of its container. Useful for row layouts, etc.