1

My objective here is that I have 2 screens and I want to show the output whenever I click using TouchableOpacity. For example, the first screen will show a Flatlist of the title from my data First,Second and Third. So what I want it to do is if I press First, it will move me to another screen and show the output FlatList a,b,c. If I press Second, it will move me to another screen and show 1,2,3. So I am not sure how to move to another screen using TouchableOpacity

This is my data

const Clusdata = 
[
{ title: 'First', 
  example: 
 [
 {name: 'a'},
 {name: 'b'},
 {name: 'c'},
 ],
},
{ title: 'Second', 
  example: 
 [
 {name: '1'},
 {name: '2'},
 {name: '3'},
 ],
},
{ title: 'Third', 
  example: 
 [
 {name: '4'},
 {name: '5'},
 {name: '6'},   
 ],
}
]

This is my Flatlist for the first screen that I can show

export default class Cluster1 extends Component{
render() {

  return (
    <View>
      <FlatList
        data={ClusData}
        renderItem={({ item, index }) => {
          return <FlatListItem item={item} index={index} />;
        }}
      />
    </View>
  );
}
}

class FlatListItem extends Component {
render() {
  return (
    <View>
      <View>
          <TouchableOpacity>
        <Text>{this.props.item.title}</Text>
        </TouchableOpacity>
      </View>
    </View>
  );
}
}

I created another class but I don't know what to store inside so I left it blank

class FlatlistExample extends Component {

}
King James
  • 59
  • 1
  • 9
  • What do you want to ask? About `Flatlist` or `TouchableOpacity `? – tuledev Jun 21 '18 at 06:54
  • TouchableOpacity. When I press First, I want it to go to another screen and show the data a,b,c in a flatlist. The part where I am not sure is the onPress function. – King James Jun 21 '18 at 07:03

2 Answers2

0

Going to another screen means navigating in react-native. React native doesn't have any out of the box navigation solutions but there are lots of navigation libraries that you can use. To be able to achieve what you want to do you need to find a suitable navigation library for your project and implement it in your project. Most of the libraries support some sort of parameter sending in navigate actions/functions. After you implemented your navigation library you can use that ability to achieve desired structure.

You can find lots of navigation related libraries in awesome-react-native repo.

bennygenel
  • 23,896
  • 6
  • 65
  • 78
  • I am using react-native-router-flex. How do I send data to another screen? – King James Jun 21 '18 at 07:29
  • You should do more research. [How to pass values to other component in React-Native-Router-Flux?](https://stackoverflow.com/q/39611634/2315280) – bennygenel Jun 21 '18 at 07:32
-1

Use this: https://github.com/aksonov/react-native-router-flux.

Send data to another view: Actions.view_name({key: value,key1:value1,key2:value2})

Hoàng Vũ Anh
  • 647
  • 1
  • 8
  • 24