Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

index.native.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. equals(this.props.url, url) || this.setState({ url: url || null });
  86. }
  87. /**
  88. * Implements React's {@link Component#render()}.
  89. *
  90. * @inheritdoc
  91. * @returns {ReactElement}
  92. */
  93. render() {
  94. const { url } = this.state;
  95. // XXX We don't render the App component until we get the initial URL.
  96. // Either it's null or some other non-null defined value.
  97. if (typeof url === 'undefined') {
  98. return null;
  99. }
  100. const {
  101. // The following props are forked in state:
  102. url: _, // eslint-disable-line no-unused-vars
  103. // The remaining props are passed through to App.
  104. ...props
  105. } = this.props;
  106. return (
  107. <App
  108. { ...props }
  109. url = { url } />
  110. );
  111. }
  112. }
  113. // Register the main/root Component.
  114. AppRegistry.registerComponent('App', () => Root);