Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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