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.

AbstractApp.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. * XXX Refer to the implementation of loadURLObject: in
  14. * ios/sdk/src/JitsiMeetView.m for further information.
  15. */
  16. timestamp: any,
  17. /**
  18. * The URL, if any, with which the app was launched.
  19. */
  20. url: Object | string
  21. };
  22. /**
  23. * Base (abstract) class for main App component.
  24. *
  25. * @abstract
  26. */
  27. export class AbstractApp extends BaseApp<Props, *> {
  28. _init: Promise<*>;
  29. /**
  30. * Initializes the app.
  31. *
  32. * @inheritdoc
  33. */
  34. componentDidMount() {
  35. super.componentDidMount();
  36. this._init.then(() => {
  37. // If a URL was explicitly specified to this React Component, then
  38. // open it; otherwise, use a default.
  39. this._openURL(toURLString(this.props.url) || this._getDefaultURL());
  40. });
  41. }
  42. /**
  43. * Implements React Component's componentDidUpdate.
  44. *
  45. * @inheritdoc
  46. */
  47. componentDidUpdate(prevProps: Props) {
  48. const previousUrl = toURLString(prevProps.url);
  49. const currentUrl = toURLString(this.props.url);
  50. const previousTimestamp = prevProps.timestamp;
  51. const currentTimestamp = this.props.timestamp;
  52. this._init.then(() => {
  53. // Deal with URL changes.
  54. if (previousUrl !== currentUrl
  55. // XXX Refer to the implementation of loadURLObject: in
  56. // ios/sdk/src/JitsiMeetView.m for further information.
  57. || previousTimestamp !== currentTimestamp) {
  58. this._openURL(currentUrl || this._getDefaultURL());
  59. }
  60. });
  61. }
  62. /**
  63. * Creates an extra {@link ReactElement}s to be added (unconditionaly)
  64. * alongside the main element.
  65. *
  66. * @abstract
  67. * @protected
  68. * @returns {ReactElement}
  69. */
  70. _createExtraElement() {
  71. return (
  72. <Fragment>
  73. <OverlayContainer />
  74. </Fragment>
  75. );
  76. }
  77. _createMainElement: (React$Element<*>, Object) => ?React$Element<*>;
  78. /**
  79. * Gets the default URL to be opened when this {@code App} mounts.
  80. *
  81. * @protected
  82. * @returns {string} The default URL to be opened when this {@code App}
  83. * mounts.
  84. */
  85. _getDefaultURL() {
  86. return getDefaultURL(this.state.store);
  87. }
  88. /**
  89. * Navigates this {@code AbstractApp} to (i.e. Opens) a specific URL.
  90. *
  91. * @param {Object|string} url - The URL to navigate this {@code AbstractApp}
  92. * to (i.e. The URL to open).
  93. * @protected
  94. * @returns {void}
  95. */
  96. _openURL(url) {
  97. this.state.store.dispatch(appNavigate(toURLString(url)));
  98. }
  99. }