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 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.
  54. Linking.getInitialURL()
  55. .then(url => this.setState({ url }))
  56. .catch(err => {
  57. console.error('Failed to get initial URL', err);
  58. // XXX Start with an empty URL if getting the initial URL fails;
  59. // otherwise, nothing will be rendered.
  60. if (this.state.url !== null) {
  61. this.setState({ url: null });
  62. }
  63. });
  64. }
  65. /**
  66. * Implements React's {@link Component#render()}.
  67. *
  68. * @inheritdoc
  69. * @returns {ReactElement}
  70. */
  71. render() {
  72. const { url } = this.state;
  73. // XXX We don't render the App component until we get the initial URL.
  74. // Either it's null or some other non-null defined value.
  75. if (typeof url === 'undefined') {
  76. return null;
  77. }
  78. const {
  79. // The following props are forked in state:
  80. url: _, // eslint-disable-line no-unused-vars
  81. // The remaining props are passed through to App.
  82. ...props
  83. } = this.props;
  84. return (
  85. <App
  86. { ...props }
  87. url = { url } />
  88. );
  89. }
  90. }
  91. // Register the main/root Component.
  92. AppRegistry.registerComponent('App', () => Root);