FlatList onClick navigate to next screen

前端 未结 1 1384
悲哀的现实
悲哀的现实 2021-02-14 18:15

How do I make a Flatlist navigate to the next screen when a row is clicked inside the Flatlist in react-native?

Edited: I posted all the codes inside my

相关标签:
1条回答
  • 2021-02-14 18:33

    i have simple example for that :

    //Tasks Component
    const Tasks = (props) => {
         const { navigate } = props.navigation;
         //function to go to next screen
         goToNextScreen = () => {
             return navigate('Detail');
         }
         return (
          <View>
            <FlatList
              data={[
                {key: 'Task 1'},
                {key: 'Task 2'},
                {key: 'Task 3'},
                {key: 'Task 4'},
                {key: 'Task 5'},
              ]}
              renderItem={({item}) => {
                  return(
                    <TouchableHighlight onPress={() => this.goToNextScreen()}>
                         <Text >{item.key}</Text>
                    </TouchableHighlight>
                  )
                }
              }
            />
          </View>
        );
    }
    
    //example for detail screen
    const Detail = (props) => {
        const { navigate } = props.navigation;
        return(
            <View><Text>Detail Screen</Text></View>
        );
    }
    
    //initial screen
    const App = StackNavigator({
      Tasks: {screen: Tasks},
      Detail: {screen: Detail},
    })
    

    maybe can help you, thanks :)

    0 讨论(0)
提交回复
热议问题