您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

index.native.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import 'es6-symbol/implement';
  2. import React, { Component } from 'react';
  3. import { AppRegistry, Linking } from 'react-native';
  4. import { App } from './features/app';
  5. /**
  6. * React Native doesn't support specifying props to the main/root component (in
  7. * the JS/JSX source code). So create a wrapper React Component (class) around
  8. * features/app's App instead.
  9. *
  10. * @extends Component
  11. */
  12. class Root extends Component {
  13. /**
  14. * {@code Root} component's property types.
  15. *
  16. * @static
  17. */
  18. static propTypes = {
  19. /**
  20. * The URL, if any, with which the app was launched.
  21. */
  22. url: React.PropTypes.string,
  23. /**
  24. * Whether the Welcome page is enabled. If {@code true}, the Welcome
  25. * page is rendered when the {@link App} is not at a location (URL)
  26. * identifying a Jitsi Meet conference/room.
  27. */
  28. welcomePageEnabled: React.PropTypes.bool
  29. };
  30. /**
  31. * Initializes a new {@code Root} instance.
  32. *
  33. * @param {Object} props - The read-only properties with which the new
  34. * instance is to be initialized.
  35. */
  36. constructor(props) {
  37. super(props);
  38. /**
  39. * The initial state of this Component.
  40. *
  41. * @type {{
  42. * url: string
  43. * }}
  44. */
  45. this.state = {
  46. /**
  47. * The URL, if any, with which the app was launched.
  48. *
  49. * @type {string}
  50. */
  51. url: this.props.url
  52. };
  53. // Handle the URL, if any, with which the app was launched. But props
  54. // have precedence.
  55. if (typeof this.props.url === 'undefined') {
  56. Linking.getInitialURL()
  57. .then(url => {
  58. if (typeof this.state.url === 'undefined') {
  59. this.setState({ url });
  60. }
  61. })
  62. .catch(err => {
  63. console.error('Failed to get initial URL', err);
  64. if (typeof this.state.url === 'undefined') {
  65. // Start with an empty URL if getting the initial URL
  66. // fails; otherwise, nothing will be rendered.
  67. this.setState({ url: null });
  68. }
  69. });
  70. }
  71. }
  72. /**
  73. * Implements React's {@link Component#componentWillReceiveProps()}.
  74. *
  75. * New props can be set from the native side by setting the appProperties
  76. * property (on iOS) or calling setAppProperties (on Android).
  77. *
  78. * @inheritdoc
  79. */
  80. componentWillReceiveProps({ url }) {
  81. if (this.props.url !== url) {
  82. this.setState({ url: url || null });
  83. }
  84. }
  85. /**
  86. * Implements React's {@link Component#render()}.
  87. *
  88. * @inheritdoc
  89. * @returns {ReactElement}
  90. */
  91. render() {
  92. const { url } = this.state;
  93. // XXX We don't render the App component until we get the initial URL.
  94. // Either it's null or some other non-null defined value.
  95. if (typeof url === 'undefined') {
  96. return null;
  97. }
  98. const {
  99. // The following props are forked in state:
  100. url: _, // eslint-disable-line no-unused-vars
  101. // The remaining props are passed through to App.
  102. ...props
  103. } = this.props;
  104. return (
  105. <App
  106. { ...props }
  107. url = { url } />
  108. );
  109. }
  110. }
  111. // Register the main/root Component.
  112. AppRegistry.registerComponent('App', () => Root);