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.

[TouchableHighlight + borderRadius] does not respect parent's overflow property/borderRadius?

See original GitHub issue

Hey guys,

Ever since I upgraded to 0.4.4, my rounded buttons have a bug in them. I have the following code

 <View  style={styles.button}>
       <TouchableHighlight style={{alignSelf: 'stretch', flex: 1}}>
               <Text>My Button</Text>
       </TouchableHighlight>
</View>

var styles = Stylesheet.create({
  button: {
       height: this.props.height,
       flexDirection: 'row',
       backgroundColor: this.props.backgroundColor,
       borderRadius: this.props.borderRadius,
       alignSelf: 'stretch',
       overflow: 'hidden',
       borderWidth: 1,
       borderColor: this.props.borderColor || this.props.backgroundColor,
       flex: 1
  }
});

The button looks great on its own but whenever you touch it, and the highlight comes in, it shows with square corners going outside of the buttons boundaries (hard to take a screenshot of).

This was working fine in 0.4.2. I have also tried matching the borderRadius style property on the TouchableHighlight component and it seems to have no effect, again in 0.4.2 it did.

Any ideas?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:12

github_iconTop GitHub Comments

4reactions
digitaltoadcommented, Jan 18, 2018

This still seems to be a bug. Setting underlayColor: 'transparent' isn’t really a fix because its removing part of the reason for using this type of view. The problem can be partially remedied by wrapping the TouchableHighlight in a View which has a borderRadius and overflow: 'hidden'.

<View style={{borderRadius: 5, overflow: 'hidden'}}>
    <TouchableHighlight onPress={() => console.warn('Pressed!')}>
        <View style={{height: 48, alignSelf: 'stretch', justifyContent: 'center', backgroundColor: '#2196F3'}}>
            <Text>Click me!</Text>
        </View>
    </TouchableHighlight>
</View>
4reactions
davidruisingercommented, Sep 26, 2016

@shahankit I solved this by adding underlayColor={ 'transparent' } to the TouchableHighlight. So my full example:

const styles = StyleSheet.create({
  touchableHightlight: {
    borderRadius: 20,
  },
  button: {
    textAlign: 'center',
    padding: 10,
    borderRadius: 20,
    fontSize: 14,
  },
  buttonLight: {
    borderWidth: 1,
    borderColor: '#FFFFFF',
    color: '#FFFFFF',
  },
})

...

<TouchableHighlight onPress={ () => { onPress } } style={ styles.touchableHightlight } underlayColor={ 'transparent' } >
  <Text style={[ styles.button, styles.buttonLight ]}>{ label }</Text>
</TouchableHighlight>

...

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native Border Radius with background color
Yes, putting the backgroundColor and borderRadius on the container, then adding overflow: 'hidden' to the container worked for me. (Also not ...
Read more >
Overflow hidden + round corners not working on Safari
This Safari bug is well known (don't know why they didn't fix it). Workaround you can find here: Safari not hiding overflow on...
Read more >
content inside element with border-radius is not clipped to ...
Image is not cropped by the border-radius of the parent element. ... (such as 'overflow' other than 'visible') also must clip to the...
Read more >
moz-border-radius + overflow:hidden does not hide children ...
-moz-border-radius + overflow:hidden does not hide children (or shadows ... Create parent with rounded corners with background (background to see easier) 2.
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