Nested Text with onPress / TouchableOpacity Bug
See original GitHub issueHey there. I found an issue when rendering nested Text elements. It’s almost the exact same as this ticket: https://github.com/facebook/react-native/issues/1030
I was able to get it to sort of work. I had to add an onPress
to the Text component.
Problems:
- TypeScript says there isn’t an
onPress
on Text elements. But it does in fact work. This should probably be fixed in the type definitons. - Not possible to use TouchableOpacity, so it doesn’t feel good when pressing on these items.
When using TouchableOpacity like this:
<Text>
<Text>first part</Text>
<TouchableOpacity><Text>Second part</Text></TouchableOpacity>
</Text>
Second part doesn’t get rendered at all.
Before you suggest using a <View>
around the <Text>
instead, please look at the referenced issue. When you do that, the text runs off screen, or wraps weirdly.
TLDR; I need to add a touchable opacity inside a nested Text component. Our api returns text in blocks, the RN app needs to parse it and render an array of text elements together with different styling.
React Native version:
0.61.4
Issue Analytics
- State:
- Created 4 years ago
- Reactions:13
- Comments:36
Top Results From Across the Web
Not working onPress in nested TouchableOpacity
When I clicked my custom component InfluencerCard , it doesn't do anything. I wonder it is because that component is in other component,...
Read more >Text - React Native
A React component for displaying text. Text supports nesting, styling, and touch handling. In the following example, the nested title and body ...
Read more >Nested TouchableOpacity Parent onPress not working-React ...
<TouchableOpacity onPress={onPress}> <TouchableOpacity disabled style={styles.button} > <Text>Press Here</Text> </TouchableOpacity> </TouchableOpacity>.
Read more >prevent touch parent on children view react native - You.com
The behavior you described works as expected. This is because TouchableOpacity is a child component of TouchableWithoutFeedback, and so the click event ...
Read more >Nested Text being Cut off - Needed Guidance : r/reactnative
<Text style={styles.textStyle}> {this.itemSentences()} <TouchableOpacity style={styles.sourceText}> [<Text onPress={this.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Not fixed yet!
It’s 2022 and we still can’t make a proper clickable text that’s inside a paragraph.
The code above, you be able to render a paragraph, but the touchable text is not properly aligned. It will be pushed up by a few pixels and I can’t find a workaround to fix it.
We have self driving cars but can’t do a proper touchable text, ironic.