react-native将数据从第二个导航传递到父导航

时间:2019-02-11 09:35:33

标签: reactjs react-native

这是第二个屏幕代码的一部分:

    state = {
      hasCameraPermission: null,
      barcodeValue : ""
    }

    FunctionToOpenFirstActivity = () =>
    {
        this.props.navigation.navigate('First', { barcodeValue: this.state.barcodeValue });
    }

    //after barcode was scanned
    handleBarCodeScanned = ({ type, data }) => {
        this.state.barcodeValue = data;
        alert(this.state.barcodeValue);

        this.FunctionToOpenFirstActivity();

    }

这是render()中父屏幕代码的一部分

   <View style={styles.firstrow}>
       <View style={styles.inputWrap}>
         <Text style={styles.label}>Barcode Value</Text>
         <TextInput style={styles.input}>{this.props.barcodeValue}</TextInput>
       </View>
   </View>

this.props.barcodeValue为空白,有人知道这是什么问题吗?

1 个答案:

答案 0 :(得分:2)

在文档https://reactnavigation.org/docs/en/params.html中可以找到,您可以使用ScrollView阅读从先前视图传递的参数,this.props.navigation.getParam(paramName, defaultValue)是可选的

根据您的情况,尝试将defaultValue更改为this.props.barcodeValue

相关问题