From 3d3f1e0ff098a695293cdb760dbc9253355f7966 Mon Sep 17 00:00:00 2001 From: akinwale Date: Thu, 10 May 2018 21:07:18 +0100 Subject: [PATCH] splash screen removed from stack after initial display (#117) --- app/src/component/AppNavigator.js | 19 ++++++++++--------- app/src/page/splash/view.js | 10 +++++++++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/src/component/AppNavigator.js b/app/src/component/AppNavigator.js index 402501ee..3d21db26 100644 --- a/app/src/component/AppNavigator.js +++ b/app/src/component/AppNavigator.js @@ -79,8 +79,8 @@ const walletStack = StackNavigator({ }); const drawer = DrawerNavigator({ - Discover: { screen: discoverStack }, - Wallet: { screen: walletStack }, + DiscoverStack: { screen: discoverStack }, + WalletStack: { screen: walletStack }, Settings: { screen: SettingsPage, navigationOptions: { drawerLockMode: 'locked-closed' } }, About: { screen: AboutPage, navigationOptions: { drawerLockMode: 'locked-closed' } } }, { @@ -110,16 +110,17 @@ class AppWithNavigationState extends React.Component { BackHandler.addEventListener('hardwareBackPress', function() { const { dispatch, navigation, nav } = this.props; // There should be a better way to check this - if (nav.routes.length > 1) { - const subRoutes = nav.routes[1].routes[0].routes; + if (nav.routes.length > 0) { + const subRoutes = nav.routes[0].routes[0].routes; const lastRoute = subRoutes[subRoutes.length - 1]; - if (['About', 'Settings'].indexOf(lastRoute.key) > -1) { - dispatch({ type: 'Navigation/BACK' }); + if (nav.routes[0].routes[0].index > 0 && + ['About', 'Settings'].indexOf(lastRoute.key) > -1) { + dispatch(NavigationActions.back()); return true; } - if (nav.routes[1].routeName === 'Main') { - if (nav.routes[1].routes[0].routes[0].index > 0) { - dispatch({ type: 'Navigation/BACK' }); + if (nav.routes[0].routeName === 'Main') { + if (nav.routes[0].routes[0].routes[0].index > 0) { + dispatch(NavigationActions.back()); return true; } } diff --git a/app/src/page/splash/view.js b/app/src/page/splash/view.js index 2e2f3965..0827092a 100644 --- a/app/src/page/splash/view.js +++ b/app/src/page/splash/view.js @@ -1,6 +1,7 @@ import React from 'react'; import { Lbry } from 'lbry-redux'; import { View, Text, NativeModules } from 'react-native'; +import { NavigationActions } from 'react-navigation'; import PropTypes from 'prop-types'; import splashStyle from '../../styles/splash'; @@ -42,7 +43,14 @@ class SplashScreen extends React.PureComponent { // Leave the splash screen const { balanceSubscribe, navigation } = this.props; balanceSubscribe(); - navigation.navigate('Main'); + + const resetAction = NavigationActions.reset({ + index: 0, + actions: [ + NavigationActions.navigate({ routeName: 'Main'}) + ] + }); + navigation.dispatch(resetAction); }); return; }