From 5ca94ee9073903140ef78506ce1d4b9d92582b45 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Tue, 26 May 2020 17:42:12 -0300 Subject: [PATCH] Navigation --- app/AppContainer.js | 9 ++------- app/lib/Navigation.js | 24 +++++++----------------- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/app/AppContainer.js b/app/AppContainer.js index c5539b02c..1c6a32603 100644 --- a/app/AppContainer.js +++ b/app/AppContainer.js @@ -5,8 +5,8 @@ import { createStackNavigator } from '@react-navigation/stack'; import { connect } from 'react-redux'; import { SafeAreaProvider, initialWindowMetrics } from 'react-native-safe-area-context'; -import { defaultHeader, onNavigationStateChange } from './utils/navigation'; import Navigation from './lib/Navigation'; +import { defaultHeader, onNavigationStateChange } from './utils/navigation'; import { ROOT_LOADING, ROOT_OUTSIDE, ROOT_NEW_SERVER, ROOT_INSIDE, ROOT_SET_USERNAME, ROOT_BACKGROUND } from './actions/app'; @@ -40,12 +40,7 @@ const App = React.memo(({ root }) => { return ( - { - Navigation.setTopLevelNavigator(navigatorRef); - }} - onNavigationStateChange={onNavigationStateChange} - > + <> {root === ROOT_LOADING ? ( diff --git a/app/lib/Navigation.js b/app/lib/Navigation.js index cbd3b44b1..4a43c356f 100644 --- a/app/lib/Navigation.js +++ b/app/lib/Navigation.js @@ -1,28 +1,18 @@ +import * as React from 'react'; import { CommonActions } from '@react-navigation/native'; -let _navigator; +const navigationRef = React.createRef(); -function setTopLevelNavigator(navigatorRef) { - _navigator = navigatorRef; +function navigate(name, params) { + navigationRef.current?.navigate(name, params); } function back() { - _navigator.dispatch( - CommonActions.back() - ); -} - -function navigate(name, params) { - _navigator.dispatch( - CommonActions.navigate({ - name, - params - }) - ); + navigationRef.current?.dispatch(CommonActions.goBack()); } export default { - back, + navigationRef, navigate, - setTopLevelNavigator + back };