我有一个问题,下面是我的代码:
import React, { Component } from 'react';
import Meteor, {
withTracker,
} from 'react-native-meteor'
import { connect } from 'react-redux';
class CreateCommunityContainer extends React.Component{
static navigationOptions = {
title: 'Community',
headerRight: (
<TouchableOpacity onPress={() => {
this.testFunction(par);
}}>
<View style={{marginRight:5}}>
<Text>NEXT</Text>
</View>
</TouchableOpacity>),
};
testFunction(par){
... some code
}
render(){
...some code
}
}
const CreateCommunityMeteor = withTracker(({userId}) => {
...some code
})(CreateCommunityContainer);
export default connect(mapStateToProps, mapDispatchToProps)(CreateCommunityMeteor);我的问题是,为什么navigationOption不被尊重或不被应用,我希望navigationOption在标题栏中给我一个标题“社区”,但它不是。但是如果我把它放在导航路由器上,它会像往常一样工作,以及如何让它生效。顺便说一句,我需要在屏幕类中定义navigationOption,而不是在路由器中,所以我可以从react导航的headerRight组件中调用该类中的函数。
发布于 2019-02-12 22:35:24
由于您已经提到,如果没有withTracker流星函数,您的组件将按预期运行,我认为问题出在withTracker没有将静态属性引入到它创建的新组件中。
您可以尝试在CreateCommunityMeteor组件上设置navigationOptions属性:
const CreateCommunityMeteor = ...
CreateCommunityMeteor.navigationOptions = {
...
};
export default connect(...)我还注意到,您在静态函数中调用了this -这不会起作用,因为静态函数没有访问类实例的权限。
同样,我建议的静态函数也不能访问它。
要解决这个问题,可以将navigationOptions设置为函数:({navigation}) => {...},并将所需内容作为参数传递给路由。
https://stackoverflow.com/questions/54649378
复制相似问题