Source

externalCode/deeplinksApi.js

/**
 * @typedef {Function} ExternalLinkNavigation
 * @param {string} path
 * @param {Object} params
 * @param {Function} navigate
 * @return {boolean | null}
 */

/**
 * @typedef {Function} DeeplinksWithoutEmbeddedCallback
 * @param {Boolean} defaultValue
 * @param {Object} linkObject Link object provided by API
 * @param {NavigationService} navigation
 * @return {Boolean}
 */

/**
 * @typedef {Function} DeeplinksFallbackCallback
 * @param {boolean} defaultValue
 * @param {Object} linkObject Link object provided by API
 * @param {NavigationService} navigation
 * @return {boolean}
 */

/**
 * @class
 * Deeplinking Hooks.
 * Instance name: deeplinksApi
  
   Hooks to modify deeplink behaviour/options when users tap on a link within the app.
 * @example
 * externalCodeSetup.deeplinksApi.METHOD_NAME
 */
export class DeeplinksApi {
	deeplinksWithoutEmbeddedReturnValueFilter = (
		defaultValue,
		linkObject,
		navigation
	) => defaultValue;

	/**
	 * Sets a function which decides if deep linking will happen. If the function returns `true`, deep linking will not happen.
	 * This is used to stop deep linking or to even try to match the route and fallback to open links in a WebView screen if the subject of navigation is not supported.
	 * You can put conditions to use this behaviour across multiple areas or one specific area within the app.
	 * @method
	 * @param {DeeplinksWithoutEmbeddedCallback} deeplinksWithoutEmbeddedReturnValueFilter
	 * @example <caption>Deep linking to profile screen will redirect to a url using page screen</caption>
	 * externalCodeSetup.deeplinksApi.setDeeplinksWithoutEmbeddedReturnValueFilter((defaultValue, linkObject, navigationService) => {
	 *  if (linkObject.action === "open_member_profile") {
	 *   navigationService.navigate({
	 *     routeName: "PageScreen",
	 *     params: {
	 *       url: "https://link-to-url.com"
	 *     }
	 *   })
	 *  }
	 *  return true;
	 * });
	 */
	setDeeplinksWithoutEmbeddedReturnValueFilter = deeplinksWithoutEmbeddedReturnValueFilter => {
		this.deeplinksWithoutEmbeddedReturnValueFilter = deeplinksWithoutEmbeddedReturnValueFilter;
	};
	deeplinksReturnValueFilter = (defaultValue, linkObject, navigation) =>
		defaultValue;

	/**
	 * Sets a function which decides what happens if deep linking fails to match the route.
	 * If the function returns `true` and deep linking fails, navigating to the WebView screen (as a default fallback) will not happen.
	 * @method
	 * @param {DeeplinksWithoutEmbeddedCallback} deeplinksWithoutEmbeddedReturnValueFilter
	 * @example <caption>Deep linking to route "inapp" fails so user would like to redirect to a different page instead</caption>
	 * externalCodeSetup.deeplinksApi.setDeeplinksReturnValueFilter((defaultValue, linkObject, navigationService) => {
	 *   if (linkObject.action === "inapp") {
	 *      navigationService.navigate({
	 *        routeName: "PageScreen",
	 *       params: {
	 *         url: "https://link-to-url.com"
	 *       }
	 *      })
	 *   }
	 *   return true;
	 * });
	 */
	setDeeplinksReturnValueFilter = deeplinksReturnValueFilter => {
		this.deeplinksReturnValueFilter = deeplinksReturnValueFilter;
	};

	externalLinkNavigate = null;
	/**
	 * @deprecated
	 * @method
	 * @param {ExternalLinkNavigation} externalLinkNavigate
	 */
	setExternalLinkNavigate = externalLinkNavigate => {
		this.externalLinkNavigate = externalLinkNavigate;
	};
}