【问题标题】:React navigation custom header反应导航自定义标题
【发布时间】:2018-12-09 09:06:55
【问题描述】:

我正在尝试像这样使用 react-navigation 自定义标头

static navigationOptions = {
    header: <EventHeader
        subscribestatus={this.props.navigation.getParam('status')}
        confirmation={this.props.navigation.getParam('confirmation')}
        deleteSubscribe={this.deleteSubscribe}
        joinEvent={this.joinEvent}
        onPress={()=>this.props.navigation.goBack()}
        eventname={this.props.navigation.getParam('title')}
    />
};

如您所见,此标题获取上一个屏幕的参数,但我正在获取 undefined 不是对象(评估 'this.props.navigation')

我做错了什么,我该如何解决?

【问题讨论】:

    标签: react-native react-navigation react-native-ios


    【解决方案1】:

    我希望你找到了解决方案,但对于其他可能来这里的人:

    navigationOptions 可以是function,它将navigator 作为第一个参数传递并可以返回一个对象。 所以你可以这样写:

    static navigationOptions = (navigator) => { return { header: ( <EventHeader subscribestatus={navigator.navigation.getParam('status')} confirmation={navigator.navigation.getParam('confirmation')} //deleteSubscribe={this.deleteSubscribe} //joinEvent={this.joinEvent} onPress={()=>navigator.navigation.goBack()} eventname={navigator.navigation.getParam('title')} /> ) } } 不幸的是,您将无法访问 this.deleteSubscribe 或 this.joinEvent

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多