Created
September 5, 2019 11:39
-
-
Save capJavert/7338d367e1b6e8a93bc14c6ae4da7f2d to your computer and use it in GitHub Desktop.
Service for cross platform handling of deep links.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Logger } from 'core/helpers' | |
class DeepLinkService { | |
init(navigation) { | |
this.navigation = navigation | |
} | |
handleUrl = (event, navigation) => { | |
try { | |
if (!event?.url) { | |
throw new Error('Url was not provided with event') | |
} | |
const [url, query = ''] = event?.url.split('?') | |
const params = query.split('&').reduce((acc, param) => { | |
const [name, value] = param.split('=') | |
if (name) { | |
acc[name] = value || true | |
} | |
return acc | |
}, {}) | |
switch (true) { | |
case url.indexOf('/') > -1: // TODO real path | |
if (params.token) { | |
// this.navigation.navigate('PasswordReset', { resetToken: params.token }) | |
} | |
break | |
default: | |
throw Error(`URL '${url}' is not supported`) | |
} | |
} catch (e) { | |
Logger.handleError(e, Logger.Severity.Warning, 'core.services.DeepLinkService') | |
} | |
} | |
} | |
export default new DeepLinkService() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment