Navigation
This commit is contained in:
parent
0bda8599c1
commit
5ca94ee907
|
@ -5,8 +5,8 @@ import { createStackNavigator } from '@react-navigation/stack';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { SafeAreaProvider, initialWindowMetrics } from 'react-native-safe-area-context';
|
import { SafeAreaProvider, initialWindowMetrics } from 'react-native-safe-area-context';
|
||||||
|
|
||||||
import { defaultHeader, onNavigationStateChange } from './utils/navigation';
|
|
||||||
import Navigation from './lib/Navigation';
|
import Navigation from './lib/Navigation';
|
||||||
|
import { defaultHeader, onNavigationStateChange } from './utils/navigation';
|
||||||
import {
|
import {
|
||||||
ROOT_LOADING, ROOT_OUTSIDE, ROOT_NEW_SERVER, ROOT_INSIDE, ROOT_SET_USERNAME, ROOT_BACKGROUND
|
ROOT_LOADING, ROOT_OUTSIDE, ROOT_NEW_SERVER, ROOT_INSIDE, ROOT_SET_USERNAME, ROOT_BACKGROUND
|
||||||
} from './actions/app';
|
} from './actions/app';
|
||||||
|
@ -40,12 +40,7 @@ const App = React.memo(({ root }) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaProvider initialMetrics={initialWindowMetrics}>
|
<SafeAreaProvider initialMetrics={initialWindowMetrics}>
|
||||||
<NavigationContainer
|
<NavigationContainer ref={Navigation.navigationRef} onNavigationStateChange={onNavigationStateChange}>
|
||||||
ref={(navigatorRef) => {
|
|
||||||
Navigation.setTopLevelNavigator(navigatorRef);
|
|
||||||
}}
|
|
||||||
onNavigationStateChange={onNavigationStateChange}
|
|
||||||
>
|
|
||||||
<Stack.Navigator screenOptions={{ headerShown: false, animationEnabled: false }}>
|
<Stack.Navigator screenOptions={{ headerShown: false, animationEnabled: false }}>
|
||||||
<>
|
<>
|
||||||
{root === ROOT_LOADING ? (
|
{root === ROOT_LOADING ? (
|
||||||
|
|
|
@ -1,28 +1,18 @@
|
||||||
|
import * as React from 'react';
|
||||||
import { CommonActions } from '@react-navigation/native';
|
import { CommonActions } from '@react-navigation/native';
|
||||||
|
|
||||||
let _navigator;
|
const navigationRef = React.createRef();
|
||||||
|
|
||||||
function setTopLevelNavigator(navigatorRef) {
|
function navigate(name, params) {
|
||||||
_navigator = navigatorRef;
|
navigationRef.current?.navigate(name, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
function back() {
|
function back() {
|
||||||
_navigator.dispatch(
|
navigationRef.current?.dispatch(CommonActions.goBack());
|
||||||
CommonActions.back()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function navigate(name, params) {
|
|
||||||
_navigator.dispatch(
|
|
||||||
CommonActions.navigate({
|
|
||||||
name,
|
|
||||||
params
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
back,
|
navigationRef,
|
||||||
navigate,
|
navigate,
|
||||||
setTopLevelNavigator
|
back
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue