2021-07-17 20:32:29 +05:00
|
|
|
import {NavigationContainer} from '@react-navigation/native';
|
2020-10-13 17:02:14 +05:00
|
|
|
import * as React from 'react';
|
2021-07-20 14:28:53 +05:00
|
|
|
import { Platform } from 'react-native';
|
2021-07-17 20:32:29 +05:00
|
|
|
import {createNativeStackNavigator} from 'react-native-screens/native-stack';
|
2020-10-13 17:02:14 +05:00
|
|
|
import Container from '../components/Container';
|
2021-07-17 20:32:29 +05:00
|
|
|
import {useSelectionStore, useSettingStore} from '../provider/stores';
|
|
|
|
|
import {eSendEvent} from '../services/EventManager';
|
2021-02-08 19:02:47 +05:00
|
|
|
import Navigation from '../services/Navigation';
|
2020-11-26 22:19:15 +05:00
|
|
|
import SettingsService from '../services/SettingsService';
|
2021-07-17 20:32:29 +05:00
|
|
|
import {history} from '../utils';
|
|
|
|
|
import {rootNavigatorRef} from '../utils/Refs';
|
2020-10-13 17:02:14 +05:00
|
|
|
import Favorites from '../views/Favorites';
|
|
|
|
|
import Folders from '../views/Folders';
|
|
|
|
|
import Home from '../views/Home';
|
|
|
|
|
import Notebook from '../views/Notebook';
|
|
|
|
|
import Notes from '../views/Notes';
|
2021-07-17 20:32:29 +05:00
|
|
|
import {Search} from '../views/Search';
|
2020-10-13 17:02:14 +05:00
|
|
|
import Settings from '../views/Settings';
|
|
|
|
|
import Tags from '../views/Tags';
|
|
|
|
|
import Trash from '../views/Trash';
|
|
|
|
|
|
2021-06-03 12:04:55 +05:00
|
|
|
const Stack = createNativeStackNavigator();
|
2020-10-13 17:02:14 +05:00
|
|
|
|
2020-11-26 23:30:42 +05:00
|
|
|
const screenOptionsForAnimation = {
|
2020-12-31 19:53:21 +05:00
|
|
|
gestureEnabled: true,
|
2021-06-07 09:51:22 +05:00
|
|
|
stackAnimation: 'none',
|
2020-11-26 23:30:42 +05:00
|
|
|
};
|
|
|
|
|
|
2020-11-14 10:04:11 +05:00
|
|
|
export const NavigatorStack = React.memo(
|
|
|
|
|
() => {
|
2021-06-15 18:26:46 +05:00
|
|
|
const [render, setRender] = React.useState(false);
|
2021-06-05 21:10:20 +05:00
|
|
|
const clearSelection = useSelectionStore(state => state.clearSelection);
|
2021-06-15 18:26:46 +05:00
|
|
|
const settings = useSettingStore(state => state.settings);
|
2021-02-15 11:00:13 +05:00
|
|
|
const onStateChange = React.useCallback(() => {
|
2021-04-11 14:04:14 +05:00
|
|
|
if (history.selectionMode) {
|
2021-06-05 21:10:20 +05:00
|
|
|
clearSelection();
|
2021-04-11 14:04:14 +05:00
|
|
|
}
|
2021-02-15 11:00:13 +05:00
|
|
|
eSendEvent('navigate');
|
|
|
|
|
});
|
2020-11-26 22:19:15 +05:00
|
|
|
|
2021-06-15 18:26:46 +05:00
|
|
|
React.useEffect(() => {
|
2021-02-19 16:03:18 +05:00
|
|
|
if (!render) {
|
|
|
|
|
setRender(true);
|
2021-03-05 11:50:51 +05:00
|
|
|
Navigation.setHeaderState(
|
2021-06-15 18:26:46 +05:00
|
|
|
settings.homepage,
|
2021-02-27 12:25:30 +05:00
|
|
|
{
|
|
|
|
|
menu: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
2021-06-15 18:26:46 +05:00
|
|
|
heading: settings.homepage,
|
|
|
|
|
id: settings.homepage.toLowerCase() + '_navigation',
|
2021-02-27 12:25:30 +05:00
|
|
|
},
|
|
|
|
|
);
|
2021-02-19 16:03:18 +05:00
|
|
|
}
|
2021-07-17 20:32:29 +05:00
|
|
|
}, [settings]);
|
2021-02-19 16:03:18 +05:00
|
|
|
|
2020-11-14 10:04:11 +05:00
|
|
|
return (
|
|
|
|
|
<Container root={true}>
|
2020-12-31 19:53:21 +05:00
|
|
|
<NavigationContainer
|
2021-02-15 11:00:13 +05:00
|
|
|
onStateChange={onStateChange}
|
2020-12-31 19:53:21 +05:00
|
|
|
independent={true}
|
|
|
|
|
ref={rootNavigatorRef}>
|
2021-09-13 08:53:16 +05:00
|
|
|
{render ? (
|
2021-02-19 16:03:18 +05:00
|
|
|
<Stack.Navigator
|
2021-07-01 10:55:34 +05:00
|
|
|
initialRouteName={settings.homepage}
|
2021-02-19 16:03:18 +05:00
|
|
|
screenOptions={{
|
|
|
|
|
headerShown: false,
|
|
|
|
|
gestureEnabled: false,
|
2021-07-20 14:28:53 +05:00
|
|
|
stackAnimation: "none",
|
2021-02-19 16:03:18 +05:00
|
|
|
}}>
|
|
|
|
|
<Stack.Screen name="Notes" component={Home} />
|
|
|
|
|
<Stack.Screen name="Notebooks" component={Folders} />
|
|
|
|
|
<Stack.Screen name="Favorites" component={Favorites} />
|
|
|
|
|
<Stack.Screen name="Trash" component={Trash} />
|
2021-07-17 20:32:29 +05:00
|
|
|
<Stack.Screen name="NotesPage" component={Notes} />
|
2021-02-19 16:03:18 +05:00
|
|
|
<Stack.Screen name="Tags" component={Tags} />
|
2021-07-17 20:32:29 +05:00
|
|
|
<Stack.Screen name="Notebook" component={Notebook} />
|
2021-02-19 16:03:18 +05:00
|
|
|
<Stack.Screen name="Settings" component={Settings} />
|
2021-07-17 20:32:29 +05:00
|
|
|
<Stack.Screen name="Search" component={Search} />
|
2021-02-19 16:03:18 +05:00
|
|
|
</Stack.Navigator>
|
2021-09-13 08:53:16 +05:00
|
|
|
) : null}
|
2020-11-14 10:04:11 +05:00
|
|
|
</NavigationContainer>
|
|
|
|
|
</Container>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
() => true,
|
|
|
|
|
);
|