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.

TouchableOpacity not clickable with negative margin on Android

See original GitHub issue

When clicking on a <TouchableOpacity /> element that a child of <View /> but is rendered outside of this view, if and only if this parent view has a backgroundColor then the TouchableOpacity will not be clickable in Android (see Snack):

Snack ReproductionAndroid Simulator
// Works - can click the circles
<View style={{ marginHorizontal: 50 }}>
  <Circle works style={{ marginLeft: -50 }} />
  <Circle works style={{ transform: [{ translateX: -50 }] }} />
  <Circle works style={{ position: 'relative', left: -50 }} />
</View>

// Broken - cannot click these circles
<View style={{ marginHorizontal: 50, backgroundColor: '#aaa' }}>
  <Circle style={{ marginLeft: -50 }} />
  <Circle style={{ transform: [{ translateX: -50 }] }} />
  <Circle style={{ position: 'relative', left: -50 }} />
</View>

React Native version:

react-native-cli: 2.0.1 react-native: 0.59.9

Steps To Reproduce

  1. Create a <View> with a backgroundColor.
  2. Add a TouchableOpacity with some sort of displacement, so that it falls outside this parent View (but still within the screen).
  3. Try to press it. There’s no feedback and no event triggered.

Describe what you expected to happen:

You can click any <TouchableOpacity /> element rendered within the screen.

Snack, code example, or link to a repository:

https://snack.expo.io/SJfRhWPlH

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:19
  • Comments:31

github_iconTop GitHub Comments

18reactions
stale[bot]commented, Feb 18, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community’s attention? This issue may be closed if no further activity occurs. You may also label this issue as a “Discussion” or add it to the “Backlog” and I will leave it open. Thank you for your contributions.

4reactions
AishwaryaSuranacommented, Jun 9, 2021

Got a hack Try Giving zIndex, It worked for me


 emailWrapper: {
    backgroundColor: 'red',
    marginBottom: -28,
    zIndex: 1,
  },
Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with TouchableOpacity, negative margin and Android
My FlatList rendered items with negative margin to superimpose them on each other. The touchable on iOS is perfect but on Android it...
Read more >
Handling Touches - React Native
TouchableOpacity can be used to provide feedback by reducing the opacity of the button, allowing the background to be seen through while the ......
Read more >
Touchable Opacity Element Is Clickable On Ios But Not Android
The React Native docs define the Touchable Opacity wrapper as: Due to TouchableOpacity's lack of styling the Button element was created as a...
Read more >
Stacking overlapping views with zIndex in Expo and React ...
Default layout. No description. import React from "react"; ...
Read more >
Button width and radius with react native android-React Native
<TouchableOpacity style={{ width:150 borderColor:'red', borderRadius:30, ... Problem with TouchableOpacity, negative margin and Android - React Native ...
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 Hashnode Post

No results found