Search code examples
reactjsscrollnativetouchableopacity

React Native TouchableOpacity scrolling


I have an old issue with scrolling some content inside TouchableOpacity (react-native). I've been trying to find any solution for months but nothing worked together with onPress/onPressIn/Out handlers. Any ideas?

<TouchableOpacity
  activeOpacity={1}
  delayPressIn={1}
  onPress={handlePress}
  onPressIn={handlePressIn}
  onLongPress={handleLongPress}
  onPressOut={handlePressOut}>
    <ScrollView>
      {/* some content to be scrolled here */}
    </ScrollView>
</TouchableOpacity>

Solution

  • use TouchableOpacity inside the Scrollview

    <ScrollView>
        <TouchableOpacity
          activeOpacity={1}
          delayPressIn={1}
          onPress={handlePress}
          onPressIn={handlePressIn}
          onLongPress={handleLongPress}
          onPressOut={handlePressOut}>
            
              {/* component to be displayed */}
           
       </TouchableOpacity>
       <TouchableOpacity
          activeOpacity={1}
          delayPressIn={1}
          onPress={handlePress}
          onPressIn={handlePressIn}
          onLongPress={handleLongPress}
          onPressOut={handlePressOut}>
            
              {/* component to be displayed */}
           
        </TouchableOpacity>
     </ScrollView>