Skip to content

Instantly share code, notes, and snippets.

@capJavert
Created September 5, 2019 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save capJavert/7338d367e1b6e8a93bc14c6ae4da7f2d to your computer and use it in GitHub Desktop.
Save capJavert/7338d367e1b6e8a93bc14c6ae4da7f2d to your computer and use it in GitHub Desktop.
Service for cross platform handling of deep links.
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