Source

externalCode/AppInitialisation.js

  1. /**
  2. * @typedef {Object} Site
  3. * @property {number} blog_id
  4. * @property {string} blogname
  5. * @property {string} domain
  6. * @property {string} path
  7. * @property {string} siteurl
  8. * @property {?string} app_home_screen_logo
  9. * @property {?string} app_splash
  10. */
  11. /**
  12. * @typedef {Object} SitesState
  13. * @property {?Array<Site>} sites
  14. * @property {?Site} selectedSite
  15. */
  16. /**
  17. * @typedef {Function} ServerUrlOverriderFunction
  18. * @param {SitesState} sitesState
  19. * @return {?string} url
  20. */
  21. /**
  22. * @class
  23. * App Initialisation Hooks.
  24. * Instance name: appInitialisationApi
  25. You can use this hook to customize your app initialization screen and help improve UX for your app.
  26. There are a range of things you can do with this hook such as loading home screen in the background, displaying splash toast message and more.
  27. * @example
  28. * externalCodeSetup.appInitialisationApi.METHOD_NAME
  29. */
  30. export class AppInitialisationApi {
  31. /**
  32. * @ignore
  33. * @private
  34. * @property {boolean} sandboxEnabled
  35. */
  36. sandboxEnabled = false;
  37. /**
  38. * @ignore
  39. * Enables connection to sandbox.
  40. * @method
  41. * @example
  42. * externalCodeSetup.appInitialisationApi.enableSandbox();
  43. */
  44. enableSandbox = () => {
  45. this.sandboxEnabled = true;
  46. };
  47. /**
  48. * @ignore
  49. * @property {string} sandBoxSessionId
  50. */
  51. sandBoxSessionId = null;
  52. /**
  53. * @ignore
  54. * @method
  55. * @example
  56. * externalCodeSetup.setSandboxSessionId(sessionId);
  57. */
  58. setSandboxSessionId = sandBoxSessionId => {
  59. this.sandBoxSessionId = sandBoxSessionId;
  60. };
  61. /**
  62. * @ignore
  63. * @property {Object} sandboxSessionHeaders
  64. */
  65. sandboxSessionHeaders = {};
  66. /**
  67. * @ignore
  68. * @method
  69. * @example
  70. * externalCodeSetup.setSandboxSessionHeaders(headers);
  71. */
  72. setSandboxSessionHeaders = headers => {
  73. this.sandboxSessionHeaders = headers;
  74. };
  75. /**
  76. * @ignore
  77. * @private
  78. * @property {boolean} enableReportSandbox
  79. */
  80. enableReportSandbox = false;
  81. /**
  82. * @ignore
  83. * If sandBoxEnabled = true, enabling this will show "Report Sandbox" link in Settings screen.
  84. * @method
  85. * @example
  86. * externalCodeSetup.appInitialisationApi.enableSandboxReport();
  87. */
  88. enableSandboxReport = () => {
  89. this.enableReportSandbox = true;
  90. };
  91. /**
  92. * @private
  93. * @property {?string} splashScreenToastText
  94. */
  95. splashScreenToastText = null;
  96. /**
  97. * The hook is used to set a splash screen toast message to show up during app initialization.
  98. * The splash screen toast message is a small message that shows up at the bottom of the screen for a while and then disappears.
  99. * It is often used to make a program more interactive and visual.
  100. * @method
  101. * @param {?String} text Sets splash screen toast message during app initialization
  102. * @example
  103. * externalCodeSetup.appInitialisationApi.setSplashScreenToastText("Welcome to my app!")
  104. */
  105. setSplashScreenToastText = text => {
  106. this.splashScreenToastText = text;
  107. };
  108. /**
  109. * @private
  110. * @property {ServerUrlOverriderFunction} initialServerUrlOverrider
  111. */
  112. initialServerUrlOverrider = sitesState => null;
  113. /**
  114. * You can use this if you are using multisite and want to override the initial `server_url` in `RootWrapper`.
  115. * For example, the hook can be used to make the app call API requests to "https://my.example.com" instead of "https://example.com" for your BuddyBoss website.
  116. * @method
  117. * @param {ServerUrlOverriderFunction} initialServerUrlOverrider Overrides initial `server_url` in `RootWrapper` for multisite user
  118. * @example
  119. * externalCodeSetup.appInitialisationApi.setInitialServerUrlOverrider((props) => {
  120. * return props.sites[1].siteurl;
  121. * })
  122. */
  123. setInitialServerUrlOverrider = initialServerUrlOverrider => {
  124. this.initialServerUrlOverrider = initialServerUrlOverrider;
  125. };
  126. /**
  127. * @private
  128. * @property {Boolean} homeScreenPrefetchEnabled
  129. */
  130. homeScreenPrefetchEnabled = false;
  131. /**
  132. * When the hook is enabled, it can help improve the UX.
  133. * It enables the home screen to load as the background of the app launch screen even before the user signs in.
  134. * When the hook is set to false, the app will only show the home screen once the user signs in.
  135. * @method
  136. * @param {Boolean} isEnabled True if home screen should be prefetched
  137. * @example
  138. * externalCodeSetup.appInitialisationApi.setHomeScreenPrefetchEnabled(true)
  139. */
  140. setHomeScreenPrefetchEnabled = isEnabled => {
  141. this.homeScreenPrefetchEnabled = isEnabled;
  142. };
  143. composeHocs = [];
  144. /**
  145. * @ignore
  146. * @method
  147. * @param {array} hocs
  148. * externalCodeSetup.appInitialisationApi.addComposeHocs(hocs)
  149. */
  150. addComposeHocs = composeHocs => {
  151. this.composeHocs = composeHocs;
  152. };
  153. }