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.

[Android] onPress not work in Android with overlapped components

See original GitHub issue

Environment

React Native Environment Info: System: OS: macOS High Sierra 10.13.6 CPU: x64 Intel® Core™ i5-5575R CPU @ 2.80GHz Memory: 34.23 MB / 8.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 8.11.3 - /usr/local/bin/node Yarn: 1.10.1 - /usr/local/bin/yarn npm: 5.6.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.0, macOS 10.14, tvOS 12.0, watchOS 5.0 Android SDK: Build Tools: 26.0.3, 27.0.3, 28.0.1 API Levels: 25, 26, 27, 28 IDEs: Android Studio: 3.1 AI-173.4907809 Xcode: 10.0/10A255 - /usr/bin/xcodebuild npmPackages: react: ^16.6.0-alpha.8af6728 => 16.6.0 react-native: ^0.57.4 => 0.57.4 npmGlobalPackages: react-native-cli: 2.0.1

Description

I have a TouchableOpacity overlapping on an Image component, but onPress can’t be fired on Android. In iOS works fine. The problem occurs in real devices and emulators of both platforms.

Inspector on Android: 46508273_908184669375588_7967715880895250432_n

Inspector on Ios: simulator screen shot - iphone 6 - 2018-11-23 at 12 54 35

Reproducible Demo

Overlap button: <View style={{ elevation: 4 }} > <TouchableOpacity style={{ width: 50, height: 50, left: scale(200), top: scale(200), right: 0, bottom: 0 }} onPress={this.showLabel} > <View> <Animated.Image source={image} style={{ width: scale(35), height: scale(35) }} /> </View> </TouchableOpacity> </View> Image: <Image source={images[imgteste]} style={{ width: width, height: verticalScale(512), resizeMode: "contain" }} />

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:38 (1 by maintainers)

github_iconTop GitHub Comments

33reactions
mayooresancommented, Aug 22, 2019

I used the TouchableOpacity from react-native instead of react-native-gesture-handler and it worked. God knows why.

32reactions
bartolkaruzacommented, Mar 8, 2019

Just make the parent at least as big as the touch area.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React native TouchableOpacity onPress not working on Android
I solved my problem in a similar way. ... I solved it by doing positioning on Touchable Opacity rather than the View. Hope...
Read more >
View - Android Developers
android:onClick, Name of the method in this View's context to invoke when the ... Returns the overlay for this view, creating it if...
Read more >
TouchableWithoutFeedback - React Native
Do not use unless you have a very good reason. All elements that respond to press should have a visual feedback when touched....
Read more >
React native TouchableOpacity onPress not working on Android
Android : React native TouchableOpacity onPress not working on Android [ Beautify Your Computer : https://www.hows.tech/p/recommended.html ] ...
Read more >
React Native Touchableopacity Onpress Not Working - ADocLib
The normal Button component does not appear visually in the app so I tried to use TouchableOpacity but onPress is not working only...
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