You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.native.js 3.6KB

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