Files
notesnook/apps/mobile/app/navigation/navigation-stack.js

132 lines
4.8 KiB
JavaScript
Raw Normal View History

2022-01-22 12:57:05 +05:00
import { NavigationContainer } from '@react-navigation/native';
2022-06-13 10:55:56 +05:00
import { createNativeStackNavigator } from '@react-navigation/native-stack';
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-07-05 14:33:48 +05:00
import Intro from '../components/intro';
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';
2022-07-05 14:33:48 +05:00
import AppLock from '../screens/settings/app-lock';
2022-02-28 15:32:55 +05:00
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';
2022-06-13 10:55:56 +05:00
import { useThemeStore } from '../stores/use-theme-store';
2022-04-24 05:59:14 +05:00
import { history } from '../utils';
import { rootNavigatorRef } from '../utils/global-refs';
2022-08-16 16:48:10 +05:00
import { hideAllTooltips } from '../hooks/use-tooltip';
2022-07-20 09:16:38 +05:00
import { useWindowDimensions } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { useSettingStore } from '../stores/use-setting-store';
2022-06-13 10:55:56 +05:00
const NativeStack = createNativeStackNavigator();
2022-07-05 14:33:48 +05:00
const IntroStack = createNativeStackNavigator();
/**
* Intro Stack:
*
* Welcome Page
* Select Privacy Mode Page
* Login/Signup Page
*
*/
const IntroStackNavigator = () => {
const colors = useThemeStore(state => state.colors);
return (
<IntroStack.Navigator
screenOptions={{
headerShown: false,
lazy: false,
animation: 'none',
contentStyle: {
backgroundColor: colors.bg
}
}}
initialRouteName={'Intro'}
>
<NativeStack.Screen name="Intro" component={Intro} />
<NativeStack.Screen name="AppLock" component={AppLock} />
</IntroStack.Navigator>
);
};
2022-04-24 05:59:14 +05:00
const Tabs = React.memo(
() => {
2022-06-13 10:55:56 +05:00
const colors = useThemeStore(state => state.colors);
2022-04-24 05:59:14 +05:00
const homepage = SettingsService.get().homepage;
2022-07-20 11:11:12 +05:00
const introCompleted = useSettingStore(state => state.settings.introCompleted);
2022-07-20 09:16:38 +05:00
const height = useSettingStore(state => state.dimensions.height);
const insets = useSafeAreaInsets();
const screenHeight = height - (50 + insets.top + insets.bottom);
2022-04-24 05:59:14 +05:00
React.useEffect(() => {
setTimeout(() => {
useNavigationStore.getState().update({ name: homepage });
}, 1000);
}, []);
return (
2022-06-13 10:55:56 +05:00
<NativeStack.Navigator
2022-04-24 05:59:14 +05:00
tabBar={() => null}
2022-07-20 11:11:12 +05:00
initialRouteName={!introCompleted ? 'Welcome' : homepage}
2022-04-24 05:59:14 +05:00
backBehavior="history"
screenOptions={{
headerShown: false,
2022-06-13 10:55:56 +05:00
lazy: false,
animation: 'none',
contentStyle: {
2022-07-20 09:16:38 +05:00
backgroundColor: colors.bg,
2022-07-20 11:11:12 +05:00
height: !introCompleted ? undefined : screenHeight
2022-06-13 10:55:56 +05:00
}
2022-04-24 05:59:14 +05:00
}}
>
2022-07-05 14:33:48 +05:00
<NativeStack.Screen name="Welcome" component={IntroStackNavigator} />
2022-06-13 10:55:56 +05:00
<NativeStack.Screen name="Notes" component={Home} />
<NativeStack.Screen name="Notebooks" component={Notebooks} />
<NativeStack.Screen options={{ lazy: true }} name="Favorites" component={Favorites} />
<NativeStack.Screen options={{ lazy: true }} name="Trash" component={Trash} />
<NativeStack.Screen options={{ lazy: true }} name="Tags" component={Tags} />
<NativeStack.Screen name="Settings" component={Settings} />
<NativeStack.Screen options={{ lazy: true }} name="TaggedNotes" component={TaggedNotes} />
<NativeStack.Screen options={{ lazy: true }} name="TopicNotes" component={TopicNotes} />
<NativeStack.Screen options={{ lazy: true }} name="ColoredNotes" component={ColoredNotes} />
<NativeStack.Screen options={{ lazy: true }} name="Monographs" component={Monographs} />
<NativeStack.Screen options={{ lazy: true }} name="Notebook" component={Notebook} />
<NativeStack.Screen options={{ lazy: true }} name="Search" component={Search} />
</NativeStack.Navigator>
2022-04-24 05:59:14 +05:00
);
},
() => 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
);