反应导航:如何通过道具和导航到其他屏幕onPressing TouchableOpacity

时间:2019-02-01 12:30:59

标签: react-native react-navigation

我正在尝试使用React native构建一个Contact App。我想将电话号码和名称传递给另一个屏幕,方法是从联系人列表中按每个按钮。

1 个答案:

答案 0 :(得分:0)

考虑查看React Navigation文档:

<Button
      title="Details"
      onPress={() => {
        /* 1. Navigate to the Details route with params */
        this.props.navigation.navigate('Details', {
          1stParamData: 'anything you want here',
          2ndParamData: 'anything you want here',
        });
      }}
    />

然后在您的导航屏幕中

const data= this.props.navigation.getParam('1stParamData', 'NO-ID'); 
//NO-ID is a fallback when there's no data.