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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import 'es6-symbol/implement';
  2. import React, { Component } from 'react';
  3. import { AppRegistry, Linking } from 'react-native';
  4. import config from './config';
  5. import { App } from './features/app';
  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. * Initializes a new Root instance.
  16. *
  17. * @param {Object} props - The read-only properties with which the new
  18. * instance is to be initialized.
  19. */
  20. constructor(props) {
  21. super(props);
  22. /**
  23. * The initial state of this Component.
  24. *
  25. * @type {{url: string}}
  26. */
  27. this.state = {
  28. /**
  29. * The URL, if any, with which the app was launched.
  30. *
  31. * @type {string}
  32. */
  33. url: undefined
  34. };
  35. // Handle the URL, if any, with which the app was launched.
  36. Linking.getInitialURL()
  37. .then(url => this.setState({ url }))
  38. .catch(err => {
  39. console.error('Failed to get initial URL', err);
  40. // XXX Start with an empty URL if getting the initial URL fails;
  41. // otherwise, nothing will be rendered.
  42. if (this.state.url !== null) {
  43. this.setState({ url: null });
  44. }
  45. });
  46. }
  47. /**
  48. * Implements React's {@link Component#render()}.
  49. *
  50. * @inheritdoc
  51. * @returns {ReactElement}
  52. */
  53. render() {
  54. // XXX We don't render the App component until we get the initial URL,
  55. // either it's null or some other non-null defined value;
  56. if (typeof this.state.url === 'undefined') {
  57. return null;
  58. }
  59. return (
  60. <App
  61. config = { config }
  62. url = { this.state.url } />
  63. );
  64. }
  65. }
  66. // Register the main Component.
  67. AppRegistry.registerComponent('App', () => Root);