Touchable* onPress not working on ScrollView composition
See original GitHub issueDescription
I have one ScrollView
(a) containing another ScrollView
(b) and a TouchableOpacity
© floating on top for (b). While scrolling on (b), onPress
on © is not triggered.
- This only happens when
scrollEventThrottle
is 50 or less - Scroll on (a) is disabled.
- It doesn’t matter the direction of (a) or (b).
Reproduction
Use the following code, scroll and press the yellow square button. The button will only work if you’re not scrolling.
import React, { Component } from 'react';
import {
AppRegistry,
View,
ScrollView,
TouchableOpacity,
Dimensions,
} from 'react-native';
const {width,height} = Dimensions.get('window');
export default class scrollplusbutton extends Component {
render() {
const color = ['green','red','blue'];
return (
<ScrollView scrollEnabled={false}>
<View style={{width, height}}>
<ScrollView scrollEventThrottle={50}>
{[...Array(20)].map((_, i) =>
<View key={i} style={{height:i*50, backgroundColor:color[i%color.length]}}/>
)}
</ScrollView>
<TouchableOpacity
style={{
position:'absolute',
left:0,
top:0,
width:100,
height:100,
backgroundColor:'yellow',
}}
onPress={()=>alert('hello!')}
/>
</View>
</ScrollView>
);
}
}
AppRegistry.registerComponent('scrollplusbutton', () => scrollplusbutton);
Additional Information
- React Native version: “react”: “15.3.2” and “react-native”: “^0.37.0”
- Platform: iOS (works well on Android)
- Operating System: MacOS
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:8 (5 by maintainers)
Top Results From Across the Web
React Native: TouchableOpacity onPress problems inside a ...
'always', the keyboard will not dismiss automatically, and the scroll view will not catch taps, but children of the scroll view can catch ......
Read more >How to improve the performance of a React Native app
Learn from this article how to improve the performance of a React Native app. Good performance is crucial for any app or product....
Read more >Common bugs in React Native ScrollView and how to fix them
React Native's ScrollView component is ubiquitous, but its implementation can sometimes lead to mistakes. Learn what to look out for here.
Read more >ScrollView - Android Developers
For vertical scrolling, consider NestedScrollView instead of scroll view which offers greater user interface flexibility and support for the material design ...
Read more >react-native-scroll-into-view - npm
scrollIntoView() web function, for ScrollView. ... android if the scroll is not working then add renderToHardwareTextureAndroid this to view ...
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 FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It appears that the ScrollView is intercepting and cancelling the onPress event. The workaround I found was to set delayPressIn={0} and attach to the onPressIn event instead of onPress.
faced same issue, solved it by wrapping the contents of
TouchableWithoutFeedback
within aView
component.