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.

Touchable* onPress not working on ScrollView composition

See original GitHub issue

Description

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:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
sachinrekhicommented, Dec 20, 2016

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.

1reaction
Sam1301commented, Mar 31, 2017

faced same issue, solved it by wrapping the contents of TouchableWithoutFeedback within a View component.

Read more comments on GitHub >

github_iconTop 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 >

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