選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

index.native.js 2.0KB

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