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

AbstractApp.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. * Implements React Component's componentDidUpdate.
  49. *
  50. * @inheritdoc
  51. */
  52. componentDidUpdate(prevProps: Props) {
  53. const previousUrl = toURLString(prevProps.url);
  54. const currentUrl = toURLString(this.props.url);
  55. const previousTimestamp = prevProps.timestamp;
  56. const currentTimestamp = this.props.timestamp;
  57. this._init.then(() => {
  58. // Deal with URL changes.
  59. if (previousUrl !== currentUrl
  60. // XXX Refer to the implementation of loadURLObject: in
  61. // ios/sdk/src/JitsiMeetView.m for further information.
  62. || previousTimestamp !== currentTimestamp) {
  63. this._openURL(currentUrl || this._getDefaultURL());
  64. }
  65. });
  66. }
  67. /**
  68. * Gets a {@code Location} object from the window with information about the
  69. * current location of the document. Explicitly defined to allow extenders
  70. * to override because React Native does not usually have a location
  71. * property on its window unless debugging remotely in which case the
  72. * browser that is the remote debugger will provide a location property on
  73. * the window.
  74. *
  75. * @public
  76. * @returns {Location} A {@code Location} object with information about the
  77. * current location of the document.
  78. */
  79. getWindowLocation() {
  80. return undefined;
  81. }
  82. /**
  83. * Creates an extra {@link ReactElement}s to be added (unconditionaly)
  84. * alongside the main element.
  85. *
  86. * @abstract
  87. * @protected
  88. * @returns {ReactElement}
  89. */
  90. _createExtraElement() {
  91. return (
  92. <Fragment>
  93. <OverlayContainer />
  94. </Fragment>
  95. );
  96. }
  97. _createMainElement: (React$Element<*>, Object) => ?React$Element<*>;
  98. /**
  99. * Gets the default URL to be opened when this {@code App} mounts.
  100. *
  101. * @protected
  102. * @returns {string} The default URL to be opened when this {@code App}
  103. * mounts.
  104. */
  105. _getDefaultURL() {
  106. return getDefaultURL(this.state.store);
  107. }
  108. /**
  109. * Navigates this {@code AbstractApp} to (i.e. Opens) a specific URL.
  110. *
  111. * @param {Object|string} url - The URL to navigate this {@code AbstractApp}
  112. * to (i.e. The URL to open).
  113. * @protected
  114. * @returns {void}
  115. */
  116. _openURL(url) {
  117. this.state.store.dispatch(appNavigate(toURLString(url)));
  118. }
  119. }