Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

index.native.js 3.7KB

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