react-native-navigation的迁移库

ContainerRegistry.js 751B

1234567891011121314151617181920212223242526272829303132
  1. import React, {Component} from 'react';
  2. import {AppRegistry} from 'react-native';
  3. export function registerContainer(containerKey, getContainerFunc) {
  4. const OriginalContainer = getContainerFunc();
  5. const NavigationContainer = wrapContainer(OriginalContainer);
  6. AppRegistry.registerComponent(containerKey, () => NavigationContainer);
  7. }
  8. function wrapContainer(OriginalContainer) {
  9. return class extends Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. allProps: {...props}
  14. };
  15. }
  16. componentWillReceiveProps(nextProps) {
  17. this.setState({
  18. allProps: {...nextProps}
  19. });
  20. }
  21. render() {
  22. return (
  23. <OriginalContainer {...this.state.allProps}/>
  24. );
  25. }
  26. };
  27. }