Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Touchable elements within FlatList / SectionList not registering #14155

Closed
Mayzie opened this issue May 24, 2017 · 8 comments
Closed

Touchable elements within FlatList / SectionList not registering #14155

Mayzie opened this issue May 24, 2017 · 8 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@Mayzie
Copy link

Mayzie commented May 24, 2017

Description

For some reason, Touchable* elements within a FlatList or SectionList view, do not register touches. Rather, it seems that upon rendering a FlatList, a touch event immediately occurs.

Reproduction Steps and Sample Code

The following, upon render, will produce an alert, "Touched". This should not happen, only on element touch. Furthermore, you cannot touch the TouchableHighlight element and have an alert popup (no highlight colours, nothing).

import {
	Alert,
	FlatList,
	TouchableHighlight,
} from 'react-native';

...

<FlatList
	data={[{'name': 'Frodo Baggins', 'address': 'Bag End, Bagshot Row, Hobbiton'}]}
	renderItem={({person}) =>
		<TouchableHighlight
			onPress={() => Alert.alert('Touched') }
			underlayColor='black'
		>
			<View>
				<Text style={{ fontSize: 24 }}>{ person.name }</Text>
				<Text>{ person.address }</Text>
			</View>
		</TouchableHighlight>
	}
	style={{ flex: 1, flexDirection: 'column', padding: 10 }}
/>

Solution

Make elements touchable within FlatList (and SectionList, which exhibits the same behaviour).

Additional Information

  • React Native version: react-native: 0.44.0
  • Platform: both
  • Development Operating System: Linux & Mac OSX Sierra
  • Dev tools: Xcode 8, react-native run-android
@marktrobinson
Copy link

marktrobinson commented Jun 5, 2017

I too am having trouble getting touchable elements to work with FlatList. In particular, TextInput

Edit - Solution: My problem was that my TextInput didn't have a height so there was nothing to tap on, add a height to your TouchableHighlight to see if that makes a difference

@bbeckk
Copy link

bbeckk commented Jun 20, 2017

same problem here too. Have you found the soln?

1 similar comment
@bbeckk
Copy link

bbeckk commented Jun 20, 2017

same problem here too. Have you found the soln?

@hailie-rei
Copy link

This solution helped me: #13649
I created a separated pure component for my FlatList item, and now Touchable event works immediately.

@pull-bot
Copy link

pull-bot commented Oct 9, 2017

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

@hramos hramos added the Icebox label Oct 9, 2017
@hramos hramos closed this as completed Oct 9, 2017
@mahgolfa
Copy link

mahgolfa commented Jul 3, 2018

I recommend u to use ListItem:
1- install react-native elements :
yarn add react-native-elements
or with npm:
npm install --save react-native-elements
2- import it to ur project :
import { ListItem } from 'react-native-elements'
3- use :
<FlatList
data= {this.state.data}
renderItem={({item}) => <ListItem
title = {item} onPress={() => Alert.alert('pressed') }
/> }
keyExtractor={(item, index) => index.toString()}
/>

for more information : https://react-native-training.github.io/react-native-elements/docs/listitem.html

@zhangyic01
Copy link

zhangyic01 commented Jul 30, 2018

Hi
I have seen exactly the same problem as Mayzie stated. I have somehow managed to find a solution. It appeared to me as a magic. I am not sure how it worked.

render() {
    return(
                <View>
                    <TouchableOpacity  onPress={null} >
                    <Card containerStyle={styles.card} >
                    <TouchableOpacity  onPress={this.onPressRecom} >
                     .....
                 </View>
      )
  }

This is basically how you do. You set onPress to null at outmost wrapper. Then you set to whatever you want to cllick. onPressRecom is my local function. It worked on me as the log appears correct.

It seems that the flatlist renderItem function will render many times, and each time it renders it automatically trigger the touch event. Making it more confusing, after it finishes rendering, click on the touch event, nothing will work. Hmmm... anyways, this hacky way worked for me. I do not know why though. Besides, I tried to follow flatlist example from https://facebook.github.io/react-native/docs/flatlist, follow "multi-select example" using pure component.

Let me know if you have proper way of doing it.

@gurol
Copy link

gurol commented Sep 13, 2018

@pull-bot: Certainly, the issue has not been fixed in a recent release and perhaps it is affecting a lot of people. 😀

@facebook facebook locked as resolved and limited conversation to collaborators Oct 9, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Oct 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

10 participants