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

Flatlist item onPress not fired during timer's setInterval function #16751

Closed
malonguwa opened this issue Nov 8, 2017 · 2 comments
Closed

Flatlist item onPress not fired during timer's setInterval function #16751

malonguwa opened this issue Nov 8, 2017 · 2 comments
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@malonguwa
Copy link

I am using FlatList to implement a carousel, and I try to use timer to increase the FlatList's offset.X, and makes it auto scrolling. But my FlatList item's TouchableOpacity onPress function never fire during the timer setInterval function which increasing the FlatList's offset.X every seconds. The Item's onPress works fine without start the timer up.

May I ask is there anything wrong for my implement? How should I implement the carousel with FlatList auto scrolling and the Item can be clicked during the scrolling?

This is the code for my FlatList and ListItem:

 <FlatList
              ref={(ref) => { this.flatListRef = ref; }}
              horizontal = {true}
              data={this.state.dataForCarousel}
              renderItem={this._renderItem}
              onScroll={this.handleScroll}
 >
 </FlatList>

  _renderItem = (item) => {
    let item1 = item;
    var txt = item1.item;
    var bgColor = item1.index % 2 == 0 ? 'red' : 'yellow';
    return (
        <TouchableOpacity
            onPress={this.clickItem}
        >
          <View
              style={{ flex: 1, alignItems: "center", justifyContent: "center",backgroundColor: bgColor, width: 80 }}>
            <Text>{txt}</Text>
          </View>
        </TouchableOpacity>
    )
  }

Here is my Timer function in componentDidMount:
``` 
      this.timer = setInterval(() => {
          this.flatListRef.scrollToOffset({ offset: this.scrollX+5});
      }, 100);

```



 
@react-native-bot
Copy link
Collaborator

@facebook-github-bot no-template

@facebook-github-bot
Copy link
Contributor

Hey @malonguwa, thanks for posting this! It looks like your issue is missing some required information. Can you please add all the details specified in the Issue Template? This is necessary for people to be able to understand and reproduce your issue. I am going to close this, but please feel free to open a new issue with the additional information provided. Thanks!

How to ContributeWhat to Expect from Maintainers

@facebook-github-bot facebook-github-bot added the Ran Commands One of our bots successfully processed a command. label Nov 8, 2017
@facebook facebook locked as resolved and limited conversation to collaborators Nov 8, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Nov 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

3 participants