import { FKNavigator } from "./../../interfaces/FKWindow"; import { ShareModule } from "../../interfaces/ShareModule"; import { NativeModule } from "../../managers/NativeModuleHelper"; import { SUCCESSFUL_EXECUTION } from "../../constants/Constants"; export default class ShareModuleImplWeb extends NativeModule implements ShareModule { public share(url: string, title: string): Promise { return new Promise((resolve) => { const navigatorObj = window.navigator as FKNavigator; if (navigatorObj && navigatorObj.share && url && title) { navigatorObj.share({ title: title || "Flipkart", text: title, url: url && decodeURIComponent(url) || window.location.href, }); } else { if (url) { const body = document.body; if (body) { const copyElem = document.createElement("textArea") as HTMLInputElement; copyElem.style.border = "0"; copyElem.style.padding = "0"; copyElem.style.margin = "0"; copyElem.style.opacity = "0"; copyElem.style.position = "absolute"; copyElem.style.left = "-9999px"; copyElem.style.top = "0px"; copyElem.setAttribute("readonly", ""); copyElem.value = url; body.appendChild(copyElem); copyElem.select(); copyElem.setSelectionRange(0, copyElem.value.length); try { if (document.queryCommandSupported("copy")) { document.execCommand("copy"); } } catch (e) { // Do Nothing } body.removeChild(copyElem); // Add Toast to show that we have copied to clipboard } } } resolve(SUCCESSFUL_EXECUTION); }) as Promise; } }