Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native Flatlist TouchableOpacity OnPress Not Working On Android

Tags:

react-native

Can some help me with this issue. On press not working in Flatlist render function. here my code. i checked other screens touch case working fine but when i try it in Flatlist it's not working



render(){
            return (
                <View style={styles.container} >
                          <FlatList
                                data={this.state.categories}
                                numColumns={2}
                                keyExtractor={item => item.id}
                                renderItem={item => this.renderItem(item)}
                            />
  </View>

 );
}

renderItem = ({item,index}) => {
        return (
          
            <TouchableOpacity onPress={() => this.moveToLocation(item.id)} style={styles.items}>
                <Image source={{uri:item.img}}
                    resizeMode="center"
                    style={styles.itemsimg} />
                <Text style={{textAlign:'center',fontSize:20, }} onPress={() => this.moveToLocation(item.id)}>{item.name}</Text>
            </TouchableOpacity>
            
        );
    }
like image 351
Sasindu Jayampathi Avatar asked Aug 09 '26 15:08

Sasindu Jayampathi


2 Answers

You need to wrap your row element (inside your renderItem method) inside tag. TouchableWithoutFeedback takes onPress as it's prop where you can provide onPress event.

For TouchableWithoutFeedback refer https://facebook.github.io/react-native/docs/touchablewithoutfeedback.html

like image 160
Dmitriy Bucaev Avatar answered Aug 12 '26 08:08

Dmitriy Bucaev


if onPress is not workingin the flatlist's render method try using onTouchStart method of the components if they have in the flatList's render method.

like image 41
Vimal Swaroop J Avatar answered Aug 12 '26 09:08

Vimal Swaroop J



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!