react-native-navigation的迁移库

ContainerRegistry.js 893B

1234567891011121314151617181920212223242526272829303132333435
  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(containerKey, OriginalContainer);
  6. AppRegistry.registerComponent(containerKey, () => NavigationContainer);
  7. }
  8. function wrapContainer(containerKey, OriginalContainer) {
  9. return class extends Component {
  10. constructor(props) {
  11. super(props);
  12. if (!props.screenId) {
  13. throw new Error(`Screen ${containerKey} does not have a screenId!`);
  14. }
  15. this.state = {
  16. allProps: {...props}
  17. };
  18. }
  19. componentWillReceiveProps(nextProps) {
  20. this.setState({
  21. allProps: {...nextProps}
  22. });
  23. }
  24. render() {
  25. return (
  26. <OriginalContainer {...this.state.allProps}/>
  27. );
  28. }
  29. };
  30. }