将navigationOptions导出为组件

时间:2017-11-02 11:52:32

标签: react-native react-native-android react-navigation

是否可以以及如何将navigationOptions导出和导入为组件

static navigationOptions = ({ navigation }) => {
return {
  headerLeft: (<Text />),
  title: (
    <Image style={{width: 500, height: 125}} source={require("../images/logo_orfo.png")} />
  ),
};

};

1 个答案:

答案 0 :(得分:0)

它不能成为React组件,因为该函数不会返回任何JSX或React.createElement实例。但是,您可以将它用作这样的模块:

NavComponent.js

//imports here

export default ({ navigation }) => {
 return {
  headerLeft: (<Text />),
  title: (
    <Image style={{width: 500, height: 125}} source=
 {require("../images/logo_orfo.png")} />
  ),
 }; 
};

然后像这样导入

import NavComponent from './NavComponent';
...
static navigationOptions = NavComponent