Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable highlighting effect of TouchableOpacity when scrolling?

<TouchableOpacity style={{ flex: 1 }} >
  <ImageBackground
    source={require('../../images/home.jpg')}>
      <View style={styles.item} collapsable={false}>
        <H3>{contentData[i].name}</H3>
        <Text>{contentData[i].description}</Text>
      </View>
  </ImageBackground>
</TouchableOpacity>

I have a list of TouchableOpacity inside a ScrollView. I want to disable highlighting effect of TouchableOpacity. When scrolling I want to highlight only when onPress event is triggered. Because it may confuse the user that it is pressed.

like image 734
Henok Tesfaye Avatar asked Sep 20 '18 08:09

Henok Tesfaye


3 Answers

Simply pass activeOpactity prop with value 1.

<TouchableOpacity activeOpacity={1}>....</TouchableOpacity>

Make sure you import TouchableOpacity from "react-native" not from "react-native-gesture-handler".

like image 153
Jeevan Prakash Avatar answered Sep 17 '22 18:09

Jeevan Prakash


Try setting the activeOpacity prop on the TouchableOpacity to 1 when scrolling. Use default settings when the user stops scrolling.

https://facebook.github.io/react-native/docs/touchableopacity#activeopacity

like image 21
codehesh Avatar answered Sep 17 '22 18:09

codehesh


You can try changing param delayPressIn. Look doc.

<TouchableOpacity delayPressIn={150} > 
 {children}
</TouchableOpacity>
like image 23
Andrey Patseiko Avatar answered Sep 21 '22 18:09

Andrey Patseiko