Files
notesnook/apps/mobile/src/navigation/navigationstack.js

84 lines
3.1 KiB
JavaScript
Raw Normal View History

2022-04-24 05:59:14 +05:00
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
2022-01-22 12:57:05 +05:00
import { NavigationContainer } from '@react-navigation/native';
2020-10-13 17:02:14 +05:00
import * as React from 'react';
2022-02-28 13:48:59 +05:00
import Container from '../components/container';
2022-02-28 15:32:55 +05:00
import Favorites from '../screens/favorites';
import Home from '../screens/home';
import Notebook from '../screens/notebook';
2022-04-24 05:59:14 +05:00
import Notebooks from '../screens/notebooks';
import { ColoredNotes } from '../screens/notes/colored';
import { Monographs } from '../screens/notes/monographs';
import { TaggedNotes } from '../screens/notes/tagged';
import { TopicNotes } from '../screens/notes/topic-notes';
2022-02-28 15:32:55 +05:00
import { Search } from '../screens/search';
import Settings from '../screens/settings';
import Tags from '../screens/tags';
import Trash from '../screens/trash';
2022-04-24 05:59:14 +05:00
import { eSendEvent } from '../services/event-manager';
import SettingsService from '../services/settings';
import useNavigationStore from '../stores/use-navigation-store';
import { useSelectionStore } from '../stores/use-selection-store';
import { history } from '../utils';
import { rootNavigatorRef } from '../utils/global-refs';
import { hideAllTooltips } from '../utils/hooks/use-tooltip';
const Tab = createBottomTabNavigator();
const Tabs = React.memo(
() => {
const homepage = SettingsService.get().homepage;
React.useEffect(() => {
setTimeout(() => {
useNavigationStore.getState().update({ name: homepage });
}, 1000);
}, []);
return (
<Tab.Navigator
tabBar={() => null}
initialRouteName={homepage}
backBehavior="history"
screenOptions={{
headerShown: false,
lazy: false
}}
>
<Tab.Screen name="Notes" component={Home} />
<Tab.Screen name="Notebooks" component={Notebooks} />
<Tab.Screen name="Favorites" component={Favorites} />
<Tab.Screen name="Trash" component={Trash} />
<Tab.Screen name="Tags" component={Tags} />
<Tab.Screen name="Settings" component={Settings} />
<Tab.Screen options={{ lazy: true }} name="TaggedNotes" component={TaggedNotes} />
<Tab.Screen options={{ lazy: true }} name="TopicNotes" component={TopicNotes} />
<Tab.Screen options={{ lazy: true }} name="ColoredNotes" component={ColoredNotes} />
<Tab.Screen options={{ lazy: true }} name="Monographs" component={Monographs} />
<Tab.Screen options={{ lazy: true }} name="Notebook" component={Notebook} />
<Tab.Screen options={{ lazy: true }} name="Search" component={Search} />
</Tab.Navigator>
);
},
() => true
);
2020-10-13 17:02:14 +05:00
2022-02-28 15:32:55 +05:00
export const NavigationStack = React.memo(
2020-11-14 10:04:11 +05:00
() => {
2021-06-05 21:10:20 +05:00
const clearSelection = useSelectionStore(state => state.clearSelection);
2022-01-08 11:33:35 +05:00
2021-02-15 11:00:13 +05:00
const onStateChange = React.useCallback(() => {
2021-04-11 14:04:14 +05:00
if (history.selectionMode) {
2021-12-31 12:35:39 +05:00
clearSelection(true);
2021-04-11 14:04:14 +05:00
}
2022-02-19 13:48:48 +05:00
hideAllTooltips();
2021-02-15 11:00:13 +05:00
eSendEvent('navigate');
});
2020-11-26 22:19:15 +05:00
2020-11-14 10:04:11 +05:00
return (
2022-04-29 00:44:21 +05:00
<Container>
2022-04-24 05:59:14 +05:00
<NavigationContainer onStateChange={onStateChange} ref={rootNavigatorRef}>
<Tabs />
2020-11-14 10:04:11 +05:00
</NavigationContainer>
</Container>
);
},
2022-01-08 11:33:35 +05:00
() => true
2020-11-14 10:04:11 +05:00
);