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

AbstractApp.js 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // @flow
  2. import React, { Fragment } from 'react';
  3. import { BaseApp } from '../../base/app';
  4. import { toURLString } from '../../base/util';
  5. import { OverlayContainer } from '../../overlay';
  6. import { appNavigate } from '../actions';
  7. import { getDefaultURL } from '../functions';
  8. /**
  9. * The type of React {@code Component} props of {@link AbstractApp}.
  10. */
  11. export type Props = {
  12. /**
  13. * The default URL {@code AbstractApp} is to open when not in any
  14. * conference/room.
  15. */
  16. defaultURL: string,
  17. /**
  18. * XXX Refer to the implementation of loadURLObject: in
  19. * ios/sdk/src/JitsiMeetView.m for further information.
  20. */
  21. timestamp: any,
  22. /**
  23. * The URL, if any, with which the app was launched.
  24. */
  25. url: Object | string
  26. };
  27. /**
  28. * Base (abstract) class for main App component.
  29. *
  30. * @abstract
  31. */
  32. export class AbstractApp extends BaseApp<Props, *> {
  33. _init: Promise<*>;
  34. /**
  35. * Initializes the app.
  36. *
  37. * @inheritdoc
  38. */
  39. componentDidMount() {
  40. super.componentDidMount();
  41. this._init.then(() => {
  42. // If a URL was explicitly specified to this React Component, then
  43. // open it; otherwise, use a default.
  44. this._openURL(toURLString(this.props.url) || this._getDefaultURL());
  45. });
  46. }
  47. /**
  48. * Notifies this mounted React {@code Component} that it will receive new
  49. * props. Makes sure that this {@code AbstractApp} has a redux store to use.
  50. *
  51. * @inheritdoc
  52. * @param {Object} nextProps - The read-only React {@code Component} props
  53. * that this instance will receive.
  54. * @returns {void}
  55. */
  56. componentWillReceiveProps(nextProps: Props) {
  57. const { props } = this;
  58. this._init.then(() => {
  59. // Deal with URL changes.
  60. let { url } = nextProps;
  61. url = toURLString(url);
  62. if (toURLString(props.url) !== url
  63. // XXX Refer to the implementation of loadURLObject: in
  64. // ios/sdk/src/JitsiMeetView.m for further information.
  65. || props.timestamp !== nextProps.timestamp) {
  66. this._openURL(url || this._getDefaultURL());
  67. }
  68. });
  69. }
  70. /**
  71. * Gets a {@code Location} object from the window with information about the
  72. * current location of the document. Explicitly defined to allow extenders
  73. * to override because React Native does not usually have a location
  74. * property on its window unless debugging remotely in which case the
  75. * browser that is the remote debugger will provide a location property on
  76. * the window.
  77. *
  78. * @public
  79. * @returns {Location} A {@code Location} object with information about the
  80. * current location of the document.
  81. */
  82. getWindowLocation() {
  83. return undefined;
  84. }
  85. /**
  86. * Creates an extra {@link ReactElement}s to be added (unconditionaly)
  87. * alongside the main element.
  88. *
  89. * @abstract
  90. * @protected
  91. * @returns {ReactElement}
  92. */
  93. _createExtraElement() {
  94. return (
  95. <Fragment>
  96. <OverlayContainer />
  97. </Fragment>
  98. );
  99. }
  100. _createMainElement: (React$Element<*>, Object) => ?React$Element<*>;
  101. /**
  102. * Gets the default URL to be opened when this {@code App} mounts.
  103. *
  104. * @protected
  105. * @returns {string} The default URL to be opened when this {@code App}
  106. * mounts.
  107. */
  108. _getDefaultURL() {
  109. return getDefaultURL(this.state.store);
  110. }
  111. /**
  112. * Navigates this {@code AbstractApp} to (i.e. Opens) a specific URL.
  113. *
  114. * @param {Object|string} url - The URL to navigate this {@code AbstractApp}
  115. * to (i.e. The URL to open).
  116. * @protected
  117. * @returns {void}
  118. */
  119. _openURL(url) {
  120. this.state.store.dispatch(appNavigate(toURLString(url)));
  121. }
  122. }