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

128 lines
3.7 KiB
JavaScript
Raw Normal View History

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';
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-15 11:00:13 +05:00
import { useTracked } from '../provider';
2020-11-26 22:19:15 +05:00
import {Actions} from '../provider/Actions';
import {eSendEvent} from '../services/EventManager';
import Navigation from '../services/Navigation';
2020-11-26 22:19:15 +05:00
import SettingsService from '../services/SettingsService';
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 = {
animationEnabled: true,
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-15 11:00:13 +05:00
const [state, dispatch] = useTracked();
const settings = state.settings;
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
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}>
2020-11-14 10:04:11 +05:00
<Stack.Navigator
2021-02-15 11:00:13 +05:00
initialRouteName={settings.homepage}
2020-11-14 10:04:11 +05:00
screenOptions={{
headerShown: false,
2020-11-26 23:30:42 +05:00
animationEnabled: false,
2020-12-31 19:53:21 +05:00
gestureEnabled: false,
2020-11-14 10:04:11 +05:00
}}>
<Stack.Screen name="Notes" component={Home} />
2020-11-26 23:30:42 +05:00
<Stack.Screen name="Notebooks" component={Folders} />
2020-11-14 10:04:11 +05:00
<Stack.Screen name="Favorites" component={Favorites} />
<Stack.Screen name="Trash" component={Trash} />
2020-11-26 23:30:42 +05:00
<Stack.Screen
options={screenOptionsForAnimation}
name="NotesPage"
component={Notes}
/>
2020-11-14 10:04:11 +05:00
<Stack.Screen name="Tags" component={Tags} />
2020-11-26 23:30:42 +05:00
<Stack.Screen
options={screenOptionsForAnimation}
name="Notebook"
component={Notebook}
/>
2020-11-14 10:04:11 +05:00
<Stack.Screen name="Settings" component={Settings} />
2020-11-26 23:30:42 +05:00
<Stack.Screen
options={screenOptionsForAnimation}
name="Search"
component={Search}
/>
2020-11-14 10:04:11 +05:00
</Stack.Navigator>
</NavigationContainer>
</Container>
);
},
() => true,
);