【问题标题】:edit source code and adding navigate in react native编辑源代码并在 React Native 中添加导航
【发布时间】:2018-06-09 10:09:33
【问题描述】:

我想对日历代码进行一些小改动,以便通过单击一周中的每一天来打开 ScanPhoto 页面。 但我不知道该怎么做。 我的计算器是正确完成的,但它不是

导航('ScanPhoto') 有语法错误,不知道怎么写

export default class Home extends Component<Props> {
  constructor(props) {
    super(props);
    this.state = {
      selectedStartDate: null,
    };
    this.onDateChange = this.onDateChange.bind(this);
  }

  onDateChange(date) {
    this.setState({
      selectedStartDate: date,
      navigate('ScanPhoto')
    });
  }


  render() {
    const { selectedStartDate } = this.state;
    const startDate = selectedStartDate ? selectedStartDate.format('jYYYY/jM/jD [is] YYYY/M/D') : '';

    const {navigate}=this.props.navigation;
    return (
      <Container>
      <Content>


      <View style={styles.container}>
      <JalaliCalendarPicker
      onDateChange={this.onDateChange}
      />

      <View>
      <Text >SELECTED DATE:{ startDate }</Text>
      </View>
      </View>



      <Button rounded light onPress={()=>navigate('calculator')}>
      <Text> calculator </Text>
      </Button>

      </Content>
      </Container>

    );
  }
}

【问题讨论】:

  • 您在 onDateChange 中的 setState 函数存在语法错误。你想在那里做什么?

标签: reactjs react-native navigation react-navigation


【解决方案1】:

要导航到新屏幕,您可以使用以下代码:

onDateChange(date) {
    this.setState({ selectedStartDate: date }) 
    this.props.navigation.navigate('ScanPhoto')
}

【讨论】:

  • thaaaaaanks ^.^
猜你喜欢
  • 1970-01-01
  • 2018-12-27
  • 1970-01-01
  • 2015-04-23
  • 2020-02-09
  • 2017-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多