反应导航传递数据并在导航上调用函数

时间:2019-01-10 10:58:37

标签: react-native react-navigation

我正在尝试传递一个变量(我可以做到),并在导航发生后立即使用该变量运行一个函数。

函数采用输入字段的值。但是,因为我将输入字段分配给了变量,所以在渲染方法上遇到了一些麻烦,因为它在导航后会覆盖数据甚至不写入数据。手动输入时可以使用,但是我也需要从相机传递此变量(也可以使用)。

主页

tabLayout.getTabAt(i).getIcon().setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.colorInactive), android.graphics.PorterDuff.Mode.MULTIPLY);

相机页面

  onChange(obj) {
    const value = obj;
    if (value) {
     this.setState({
      buttonDisabled: false,
      text: value,
     });
    } else {
     this.setState({
      buttonDisabled: true,
      text: ''
    });
   }
  };


render() {
    const { navigation } = this.props;
    const scanCode = navigation.getParam('text', '');

    return (
      <View style={{padding: 30, paddingTop: 40}}>
        <TextInput autoFocus
          ref='queryInput'
          style={{height: 40}}
          placeholder="placeholder.."
          value={scanCode === '' ? this.state.text : scanCode}
          onChangeText={this.onChange.bind(this)}
          onSubmitEditing={this.runQuery}
        />
        <Button
          onPress={this.runQuery}
          title="run"
          color="#841584"
          accessibilityLabel="query"
          disabled={this.state.buttonDisabled}
        />
      <Button title='Camera' style={{position: 'absolute', bottom: 0, left: 0}} onPress={() => this.gotoCamera()}></Button>
      </View>
    );
  }
};

是否可以在“相机页面”的“主页”中设置值的状态,或者我应该在这里做什么?

谢谢

0 个答案:

没有答案