add support for special links (#369)

This commit is contained in:
Akinwale Ariwodola 2018-12-01 23:56:33 +01:00 committed by GitHub
parent 48b92ed2a6
commit f3316160fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View file

@ -6,6 +6,11 @@ const Constants = {
ACTION_DELETE_COMPLETED_BLOBS: "DELETE_COMPLETED_BLOBS",
ACTION_FIRST_RUN_PAGE_CHANGED: "FIRST_RUN_PAGE_CHANGED",
PAGE_REWARDS: 'rewards',
PAGE_SETTINGS: 'settings',
PAGE_TRENDING: 'trending',
PAGE_WALLET: 'wallet'
};
export default Constants;

View file

@ -1,6 +1,27 @@
import { NavigationActions, StackActions } from 'react-navigation';
import Constants from '../constants';
function getRouteForSpecialUri(uri) {
let targetRoute;
const page = uri.substring(8).trim(); // 'lbry://?'.length == 8
switch (page) {
case Constants.PAGE_REWARDS: targetRoute = 'Rewards'; break;
case Constants.PAGE_SETTINGS: targetRoute = 'Settings'; break;
case Constants.PAGE_TRENDING: targetRoute = 'TrendingStack'; break;
case Constants.PAGE_WALLET: targetRoute = 'WalletStack'; break;
default: targetRoute = 'DiscoverStack'; break;
}
return targetRoute;
}
export function dispatchNavigateToUri(dispatch, nav, uri) {
if (uri.startsWith('lbry://?')) {
dispatch(NavigationActions.navigate({ routeName: getRouteForSpecialUri(uri) }));
return;
}
const params = { uri };
if (nav && nav.routes && nav.routes.length > 0 && 'Main' === nav.routes[0].routeName) {
const mainRoute = nav.routes[0];
@ -48,6 +69,11 @@ export function navigateToUri(navigation, uri, additionalParams) {
return;
}
if (uri.startsWith('lbry://?')) {
navigation.navigate({ routeName: getRouteForSpecialUri(uri) });
return;
}
const params = Object.assign({ uri }, additionalParams);
if ('File' === navigation.state.routeName) {
const stackAction = StackActions.replace({ routeName: 'File', newKey: uri, params });