调用函数作为组件React-Native

时间:2018-10-20 22:25:30

标签: react-native drawer navigator

我想使用状态来操纵DrawerNavigator参数,并将其设置在componentWillMount()上。

这里的问题是:如何在react-native中调用函数作为组件?

render方法应该更新:

class App extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      param0: "",
      param1: ""
    };
    this.Drawer = this.Drawer.bind(this);
  }

  Drawer() {
    return createDrawerNavigator({
      Screen0: {
        screen: Screen2Module,
        params: {
          screenTitle: this.state.param0,
        },
      },
      Screen1: {
        screen: Screen1Module,
        params: {
          screenTitle: this.state.param1,
        },
      } 
    });
  }

  componentWillMount() {
    Locales((locales) => this.setState({
      param0: locales.param0,
      param1: locales.param1
    }));
  }

  static router = () => this.Drawer().router;
  static navigationOptions = () => this.Drawer().navigationOptions;


  render() {
    return <Drawer navigation={this.props.navigation} />;
  }
}

export default App;

0 个答案:

没有答案