add support for special links (#369)
This commit is contained in:
parent
48b92ed2a6
commit
f3316160fb
2 changed files with 31 additions and 0 deletions
|
@ -6,6 +6,11 @@ const Constants = {
|
||||||
|
|
||||||
ACTION_DELETE_COMPLETED_BLOBS: "DELETE_COMPLETED_BLOBS",
|
ACTION_DELETE_COMPLETED_BLOBS: "DELETE_COMPLETED_BLOBS",
|
||||||
ACTION_FIRST_RUN_PAGE_CHANGED: "FIRST_RUN_PAGE_CHANGED",
|
ACTION_FIRST_RUN_PAGE_CHANGED: "FIRST_RUN_PAGE_CHANGED",
|
||||||
|
|
||||||
|
PAGE_REWARDS: 'rewards',
|
||||||
|
PAGE_SETTINGS: 'settings',
|
||||||
|
PAGE_TRENDING: 'trending',
|
||||||
|
PAGE_WALLET: 'wallet'
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Constants;
|
export default Constants;
|
||||||
|
|
|
@ -1,6 +1,27 @@
|
||||||
import { NavigationActions, StackActions } from 'react-navigation';
|
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) {
|
export function dispatchNavigateToUri(dispatch, nav, uri) {
|
||||||
|
if (uri.startsWith('lbry://?')) {
|
||||||
|
dispatch(NavigationActions.navigate({ routeName: getRouteForSpecialUri(uri) }));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const params = { uri };
|
const params = { uri };
|
||||||
if (nav && nav.routes && nav.routes.length > 0 && 'Main' === nav.routes[0].routeName) {
|
if (nav && nav.routes && nav.routes.length > 0 && 'Main' === nav.routes[0].routeName) {
|
||||||
const mainRoute = nav.routes[0];
|
const mainRoute = nav.routes[0];
|
||||||
|
@ -48,6 +69,11 @@ export function navigateToUri(navigation, uri, additionalParams) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (uri.startsWith('lbry://?')) {
|
||||||
|
navigation.navigate({ routeName: getRouteForSpecialUri(uri) });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const params = Object.assign({ uri }, additionalParams);
|
const params = Object.assign({ uri }, additionalParams);
|
||||||
if ('File' === navigation.state.routeName) {
|
if ('File' === navigation.state.routeName) {
|
||||||
const stackAction = StackActions.replace({ routeName: 'File', newKey: uri, params });
|
const stackAction = StackActions.replace({ routeName: 'File', newKey: uri, params });
|
||||||
|
|
Loading…
Reference in a new issue