[Text on Android]: setting selectable to true breaks the text truncation and lineHeight on Android
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 127k
- Forks
- 25.3k
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 4
Description
Description
I use Text component that has to contain selectable text and should be truncated if it extends the width of the parent component.
On iOS everything works fine. On Android if I set selectable={true} truncation and line height of the text are breaking.
Steps to reproduce
- import Text component from react-native
- render Text component, add
selectable={true},numberOfLines={1} - the text is cut off instead of being truncated, the line height is bigger than it should be, the top of the second line of text is visible
React Native Version
0.75.4
Affected Platforms
Runtime - Android
Output of npx react-native info
-
Stacktrace or Logs
-
Reproducer
https://github.com/dariakoko/text-component-on-android
Screenshots and Videos
<View style={{width: 200}}>
<Text style={{color: 'green'}}>default: </Text>
<Text style={{backgroundColor: 'yellow'}}>
Some long very very very very very long text
</Text>
<Text>-------------</Text>
<Text style={{color: 'green'}}>not selectable: </Text>
<Text numberOfLines={1} style={{backgroundColor: 'yellow'}}>
Some long very very very very very long text
</Text>
<Text>-------------</Text>
<Text style={{color: 'red'}}>selectable (issue): </Text>
<Text
selectable={true}
numberOfLines={1}
style={{backgroundColor: 'yellow'}}>
Some long very very very very very long text
</Text>
<View style={{height: 20, backgroundColor: 'pink'}}></View>
</View>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked reproducer at https://github.com/dariakoko/text-component-on-android and inspect the React Native Text component behavior on Android with selectable={true} and numberOfLines={1}. Compare it with the non-selectable and iOS cases; done means selectable text truncates correctly and preserves the expected line height on Android.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, react-native
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100