Search code examples
javascriptreact-nativelistviewscrollscrollview

Make TouchableOpacity not highlight element when starting to scroll [React Native]


TouchableOpacity makes things touchable, or as React Native says:

A wrapper for making views respond properly to touches.

But using it inside a ScrollView or ListView results in highlighting when we (or at least I) do not want that.

These are three steps involved in scrolling down a ListView filled with elements:

  • Touch an element
  • Move finger up
  • Release finger

Touching the element immediately results in a highlight animation. But in this case, we just want to scroll. We do not want to do anything with that element, be it highlighting or opening a detail view etc.

This does not happen all the time but most of the times on my Android device.

What is a proper way of handling this?


Solution

  • A scroll gesture should cancel the TouchableOpacity touch responder, but if you think the TouchableOpacity highlight is triggered to early, you can try tweaking the delayPressIn property.