question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nested Text with onPress / TouchableOpacity Bug

See original GitHub issue

Hey 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:open
  • Created 4 years ago
  • Reactions:13
  • Comments:36

github_iconTop GitHub Comments

14reactions
backmeupplzcommented, Dec 25, 2020

Not fixed yet!

9reactions
aprilmintacpinedacommented, Feb 13, 2022

It’s 2022 and we still can’t make a proper clickable text that’s inside a paragraph.

<Text
  style={{
    marginTop: 45,
    width: 167,
    textAlign: 'center'
  }}
>
  Don’t have an account yet?{' '}
  <TouchableOpacity
    onPress={() => {
      console.log('fuck');
    }}
  >
    <Text style={{ color: 'red' }}>Create account</Text>
  </TouchableOpacity>{' '}
  now!
</Text>

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found