expo#Linking TypeScript Examples

The following examples show how to use expo#Linking. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: links.ts    From companion-kit with MIT License 6 votes vote down vote up
export async function tryOpenLink(url: string = OpenEmailClient, alert = true) {
    const supported = await Linking.canOpenURL(url);
    if (supported) {
        Linking.openURL(url);
        return true;
    } else if (alert) {
        Alert.alert('Error', 'We wasn\'t able to open the link. Possibly, it hasn\'t been configured in your system.');
        return false;
    }
}
Example #2
Source File: AppQueryService.ts    From companion-kit with MIT License 6 votes vote down vote up
private _onDeepLinkHandler = (e: { url: string }) => {
        // work around for multiple link received
        const now = new Date().getTime();
        const elapsed = this._deepLinkReceivedTime ? now - this._deepLinkReceivedTime : Number.MAX_VALUE;
        this._deepLinkReceivedTime = now;

        if (elapsed < 1000) {
            return;
        }

        if (!e.url) {
            return;
        }

        const result: ParsedURL = e.url && Linking.parse(e.url);
        logger.log('__PARSED LINK', result);

        const params: AppQueryParameters = { };

        if (result.queryParams?.link) {
            const linkParsed = Linking.parse(result.queryParams.link);
            params.mode = linkParsed.queryParams?.mode;
            params.oobCode = linkParsed.queryParams?.oobCode;

            if (linkParsed?.queryParams?.continueUrl) {
                const continueUrlParsed = Linking.parse(linkParsed?.queryParams?.continueUrl);
                params.appParams = continueUrlParsed?.queryParams;
            }
        } else {
            params.appParams = result.queryParams || { };
        }

        transaction(() => {
            this._currentUrl = e.url;
            this._query = params;
            this._pathname = result.path;
        });
    }
Example #3
Source File: AppQueryService.ts    From companion-kit with MIT License 5 votes vote down vote up
dispose() {
        Linking.removeEventListener('url', this._onDeepLinkHandler);
    }
Example #4
Source File: AppQueryService.ts    From companion-kit with MIT License 5 votes vote down vote up
constructor() {
        Linking.addEventListener('url', this._onDeepLinkHandler);
        Linking.getInitialURL()
            .then(url => this._onDeepLinkHandler({ url }));
    }