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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 => this.setState({ url }))
  58. .catch(err => {
  59. console.error('Failed to get initial URL', err);
  60. // Start with an empty URL if getting the initial URL fails;
  61. // otherwise, nothing will be rendered.
  62. this.setState({ url: null });
  63. });
  64. }
  65. }
  66. /**
  67. * Implements React's {@link Component#componentWillReceiveProps()}.
  68. *
  69. * New props can be set from the native side by setting the appProperties
  70. * property (on iOS) or calling setAppProperties (on Android).
  71. *
  72. * @inheritdoc
  73. */
  74. componentWillReceiveProps({ url }) {
  75. if (this.props.url !== url) {
  76. this.setState({ url: url || null });
  77. }
  78. }
  79. /**
  80. * Implements React's {@link Component#render()}.
  81. *
  82. * @inheritdoc
  83. * @returns {ReactElement}
  84. */
  85. render() {
  86. const { url } = this.state;
  87. // XXX We don't render the App component until we get the initial URL.
  88. // Either it's null or some other non-null defined value.
  89. if (typeof url === 'undefined') {
  90. return null;
  91. }
  92. const {
  93. // The following props are forked in state:
  94. url: _, // eslint-disable-line no-unused-vars
  95. // The remaining props are passed through to App.
  96. ...props
  97. } = this.props;
  98. return (
  99. <App
  100. { ...props }
  101. url = { url } />
  102. );
  103. }
  104. }
  105. // Register the main/root Component.
  106. AppRegistry.registerComponent('App', () => Root);