TouchableOpacity not clickable with negative margin on Android
See original GitHub issueWhen 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 Reproduction | Android 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
- Create a
<View>
with a backgroundColor. - Add a TouchableOpacity with some sort of displacement, so that it falls outside this parent View (but still within the screen).
- 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:
Issue Analytics
- State:
- Created 4 years ago
- Reactions:19
- Comments:31
Top 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 >
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 Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
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.
Got a hack Try Giving zIndex, It worked for me