Source

externalCode/AppInitialisation.js

/**
 * @typedef {Object} Site
 * @property {number} blog_id
 * @property {string} blogname
 * @property {string} domain
 * @property {string} path
 * @property {string} siteurl
 * @property {?string} app_home_screen_logo
 * @property {?string} app_splash
 */

/**
 * @typedef {Object} SitesState
 * @property {?Array<Site>} sites
 * @property {?Site} selectedSite
 */

/**
 * @typedef {Function} ServerUrlOverriderFunction
 * @param {SitesState} sitesState
 * @return {?string} url
 */

/**
 * @class
 * App Initialisation Hooks.
 * Instance name: appInitialisationApi
  
   You can use this hook to customize your app initialization screen and help improve UX for your app. 
   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.
 * @example
 * externalCodeSetup.appInitialisationApi.METHOD_NAME
 */
export class AppInitialisationApi {
	/**
	 * @ignore
	 * @private
	 * @property {boolean} sandboxEnabled
	 */
	sandboxEnabled = false;

	/**
	 * @ignore
	 * Enables connection to sandbox.
	 * @method
	 * @example
	 * externalCodeSetup.appInitialisationApi.enableSandbox();
	 */
	enableSandbox = () => {
		this.sandboxEnabled = true;
	};

	/**
	 * @ignore
	 * @private
	 * @property {boolean} enableReportSandbox
	 */
	enableReportSandbox = false;

	/**
	 * @ignore
	 * If sandBoxEnabled = true, enabling this will show "Report Sandbox" link in Settings screen.
	 * @method
	 * @example
	 * externalCodeSetup.appInitialisationApi.enableSandboxReport();
	 */
	enableSandboxReport = () => {
		this.enableReportSandbox = true;
	};

	/**
	 * @private
	 * @property {?string} splashScreenToastText
	 */
	splashScreenToastText = null;

	/**
	 * The hook is used to set a splash screen toast message to show up during app initialization.
	 * The splash screen toast message is a small message that shows up at the bottom of the screen for a while and then disappears.
	 * It is often used to make a program more interactive and visual.
	 * @method
	 * @param {?String} text Sets splash screen toast message during app initialization
	 * @example
	 * externalCodeSetup.appInitialisationApi.setSplashScreenToastText("Welcome to my app!")
	 */
	setSplashScreenToastText = text => {
		this.splashScreenToastText = text;
	};

	/**
	 * @private
	 * @property {ServerUrlOverriderFunction} initialServerUrlOverrider
	 */
	initialServerUrlOverrider = sitesState => null;

	/**
	 * You can use this if you are using multisite and want to override the initial `server_url` in `RootWrapper`.
	 * 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.
	 * @method
	 * @param {ServerUrlOverriderFunction} initialServerUrlOverrider Overrides initial `server_url` in `RootWrapper` for multisite user
	 * @example
	 * externalCodeSetup.appInitialisationApi.setInitialServerUrlOverrider((props) => {
	 *  return props.sites[1].siteurl;
	 * })
	 */
	setInitialServerUrlOverrider = initialServerUrlOverrider => {
		this.initialServerUrlOverrider = initialServerUrlOverrider;
	};

	/**
	 * @private
	 * @property {Boolean} homeScreenPrefetchEnabled
	 */
	homeScreenPrefetchEnabled = false;
	/**
	 * When the hook is enabled, it can help improve the UX.
	 * It enables the home screen to load as the background of the app launch screen even before the user signs in.
	 * When the hook is set to false, the app will only show the home screen once the user signs in.
	 * @method
	 * @param {Boolean} isEnabled True if home screen should be prefetched
	 * @example
	 * externalCodeSetup.appInitialisationApi.setHomeScreenPrefetchEnabled(true)
	 */
	setHomeScreenPrefetchEnabled = isEnabled => {
		this.homeScreenPrefetchEnabled = isEnabled;
	};
}