diff --git a/src/navigation/service.js b/src/navigation/service.js index 5968e70fb..8be379790 100644 --- a/src/navigation/service.js +++ b/src/navigation/service.js @@ -1,3 +1,4 @@ +import { BackHandler } from 'react-native'; import { NavigationActions } from 'react-navigation'; let _navigator; @@ -24,6 +25,17 @@ const navigate = (navigationProps) => { } }; +const navigateBack = () => { + if (_navigator) { + const { index } = _navigator.state.nav.routes[0]; + if (index) { + _navigator.dispatch(NavigationActions.back()); + } else { + BackHandler.exitApp(); + } + } +}; + // add other navigation functions that you need and export them -export { navigate, setTopLevelNavigator }; +export { navigate, setTopLevelNavigator, navigateBack }; diff --git a/src/screens/application/container/applicationContainer.tsx b/src/screens/application/container/applicationContainer.tsx index 6eebf14fd..6fac05852 100644 --- a/src/screens/application/container/applicationContainer.tsx +++ b/src/screens/application/container/applicationContainer.tsx @@ -49,7 +49,7 @@ import { getUnreadNotificationCount, } from '../../../providers/ecency/ecency'; import { fetchLatestAppVersion } from '../../../providers/github/github'; -import { navigate } from '../../../navigation/service'; +import { navigate, navigateBack } from '../../../navigation/service'; // Actions import { @@ -566,14 +566,15 @@ class ApplicationContainer extends Component { }; _onBackPress = () => { + navigateBack(); + /* const { dispatch, nav } = this.props; - if (nav && nav[0].index !== 0) { dispatch(NavigationActions.back()); } else { BackHandler.exitApp(); } - + */ return true; };