2020-11-26 22:19:15 +05:00
|
|
|
import {NavigationContainer} from '@react-navigation/native';
|
|
|
|
|
import {createStackNavigator} from '@react-navigation/stack';
|
2020-10-13 17:02:14 +05:00
|
|
|
import * as React from 'react';
|
2020-11-26 22:19:15 +05:00
|
|
|
import {Animated} from 'react-native';
|
2021-02-19 16:03:18 +05:00
|
|
|
import SplashScreen from 'react-native-splash-screen';
|
2020-10-13 17:02:14 +05:00
|
|
|
import Container from '../components/Container';
|
2020-11-26 22:19:15 +05:00
|
|
|
import {updateEvent} from '../components/DialogManager/recievers';
|
2021-02-19 16:03:18 +05:00
|
|
|
import {useTracked} from '../provider';
|
2020-11-26 22:19:15 +05:00
|
|
|
import {Actions} from '../provider/Actions';
|
2021-02-19 16:03:18 +05:00
|
|
|
import {
|
|
|
|
|
eSendEvent,
|
|
|
|
|
eSubscribeEvent,
|
|
|
|
|
eUnSubscribeEvent,
|
|
|
|
|
} 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-02-19 16:03:18 +05:00
|
|
|
import {eOpenSideMenu} from '../utils/Events';
|
2020-11-26 22:19:15 +05:00
|
|
|
import {rootNavigatorRef} from '../utils/Refs';
|
|
|
|
|
import {sleep} from '../utils/TimeUtils';
|
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';
|
2020-11-26 22:19:15 +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';
|
|
|
|
|
|
|
|
|
|
const Stack = createStackNavigator();
|
|
|
|
|
|
2020-11-04 16:52:47 +05:00
|
|
|
const forFade = ({current}) => ({
|
|
|
|
|
cardStyle: {
|
|
|
|
|
opacity: current.progress,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const forSlide = ({current, next, inverted, layouts: {screen}}) => {
|
|
|
|
|
const progress = Animated.add(
|
|
|
|
|
current.progress.interpolate({
|
|
|
|
|
inputRange: [0, 1],
|
|
|
|
|
outputRange: [0, 1],
|
|
|
|
|
extrapolate: 'clamp',
|
|
|
|
|
}),
|
|
|
|
|
next
|
|
|
|
|
? next.progress.interpolate({
|
|
|
|
|
inputRange: [0, 1],
|
|
|
|
|
outputRange: [0, 1],
|
|
|
|
|
extrapolate: 'clamp',
|
|
|
|
|
})
|
|
|
|
|
: 0,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
cardStyle: {
|
|
|
|
|
transform: [
|
|
|
|
|
{
|
|
|
|
|
translateX: Animated.multiply(
|
|
|
|
|
progress.interpolate({
|
|
|
|
|
inputRange: [0, 1, 2],
|
|
|
|
|
outputRange: [
|
|
|
|
|
screen.width, // Focused, but offscreen in the beginning
|
|
|
|
|
0, // Fully focused
|
|
|
|
|
screen.width * -0.3, // Fully unfocused
|
|
|
|
|
],
|
|
|
|
|
extrapolate: 'clamp',
|
|
|
|
|
}),
|
|
|
|
|
inverted,
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2020-11-26 23:30:42 +05:00
|
|
|
const screenOptionsForAnimation = {
|
2021-04-09 10:27:46 +05:00
|
|
|
animationEnabled: false,
|
2020-11-26 23:30:42 +05:00
|
|
|
cardStyleInterpolator: forSlide,
|
2020-12-31 19:53:21 +05:00
|
|
|
gestureEnabled: true,
|
2020-11-26 23:30:42 +05:00
|
|
|
};
|
|
|
|
|
|
2020-11-14 10:04:11 +05:00
|
|
|
export const NavigatorStack = React.memo(
|
|
|
|
|
() => {
|
2021-02-19 16:03:18 +05:00
|
|
|
const [, dispatch] = useTracked();
|
|
|
|
|
const [render, setRender] = React.useState(false);
|
2021-02-15 11:00:13 +05:00
|
|
|
const onStateChange = React.useCallback(() => {
|
|
|
|
|
dispatch({type: Actions.SELECTION_MODE, enabled: false});
|
|
|
|
|
dispatch({type: Actions.CLEAR_SELECTION});
|
|
|
|
|
eSendEvent('navigate');
|
|
|
|
|
});
|
2020-11-26 22:19:15 +05:00
|
|
|
|
2021-02-19 16:03:18 +05:00
|
|
|
const updateRender = async () => {
|
|
|
|
|
if (!render) {
|
|
|
|
|
setRender(true);
|
2021-03-05 11:50:51 +05:00
|
|
|
Navigation.setHeaderState(
|
2021-02-27 12:25:30 +05:00
|
|
|
SettingsService.get().homepage,
|
|
|
|
|
{
|
|
|
|
|
menu: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
heading: SettingsService.get().homepage,
|
|
|
|
|
id: SettingsService.get().homepage.toLowerCase() + '_navigation',
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
2021-02-19 16:03:18 +05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
eSubscribeEvent(eOpenSideMenu, updateRender);
|
|
|
|
|
return () => {
|
|
|
|
|
eUnSubscribeEvent(eOpenSideMenu, updateRender);
|
|
|
|
|
};
|
2021-02-24 11:00:45 +05:00
|
|
|
}, [render]);
|
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-02-19 16:03:18 +05:00
|
|
|
{render && (
|
|
|
|
|
<Stack.Navigator
|
|
|
|
|
initialRouteName={SettingsService.get().homepage}
|
|
|
|
|
screenOptions={{
|
|
|
|
|
headerShown: false,
|
|
|
|
|
animationEnabled: false,
|
|
|
|
|
gestureEnabled: false,
|
|
|
|
|
}}>
|
|
|
|
|
<Stack.Screen name="Notes" component={Home} />
|
|
|
|
|
<Stack.Screen name="Notebooks" component={Folders} />
|
|
|
|
|
<Stack.Screen name="Favorites" component={Favorites} />
|
|
|
|
|
<Stack.Screen name="Trash" component={Trash} />
|
|
|
|
|
<Stack.Screen
|
|
|
|
|
options={screenOptionsForAnimation}
|
|
|
|
|
name="NotesPage"
|
|
|
|
|
component={Notes}
|
|
|
|
|
/>
|
|
|
|
|
<Stack.Screen name="Tags" component={Tags} />
|
|
|
|
|
<Stack.Screen
|
|
|
|
|
options={screenOptionsForAnimation}
|
|
|
|
|
name="Notebook"
|
|
|
|
|
component={Notebook}
|
|
|
|
|
/>
|
|
|
|
|
<Stack.Screen name="Settings" component={Settings} />
|
|
|
|
|
<Stack.Screen
|
|
|
|
|
options={screenOptionsForAnimation}
|
|
|
|
|
name="Search"
|
|
|
|
|
component={Search}
|
|
|
|
|
/>
|
|
|
|
|
</Stack.Navigator>
|
|
|
|
|
)}
|
2020-11-14 10:04:11 +05:00
|
|
|
</NavigationContainer>
|
|
|
|
|
</Container>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
() => true,
|
|
|
|
|
);
|