您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

index.native.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 the application was launched with, but props have
  54. // 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(nextProps) {
  75. this.setState({ url: nextProps.url || null });
  76. }
  77. /**
  78. * Implements React's {@link Component#render()}.
  79. *
  80. * @inheritdoc
  81. * @returns {ReactElement}
  82. */
  83. render() {
  84. const { url } = this.state;
  85. // XXX We don't render the App component until we get the initial URL.
  86. // Either it's null or some other non-null defined value.
  87. if (typeof url === 'undefined') {
  88. return null;
  89. }
  90. const {
  91. // The following props are forked in state:
  92. url: _, // eslint-disable-line no-unused-vars
  93. // The remaining props are passed through to App.
  94. ...props
  95. } = this.props;
  96. return (
  97. <App
  98. { ...props }
  99. url = { url } />
  100. );
  101. }
  102. }
  103. // Register the main/root Component.
  104. AppRegistry.registerComponent('App', () => Root);