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

102 lines
2.9 KiB
JavaScript
Raw Normal View History

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';
import { Animated } from 'react-native';
2020-10-13 17:02:14 +05:00
import Container from '../components/Container';
import { useTracked } from '../provider';
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';
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-14 10:04:11 +05:00
export const NavigatorStack = React.memo(
() => {
const [state] = useTracked();
const {settings} = state;
2020-11-20 02:43:07 +05:00
2020-11-14 10:04:11 +05:00
return (
<Container root={true}>
<NavigationContainer independent={true} ref={rootNavigatorRef}>
<Stack.Navigator
initialRouteName={settings.homepage}
screenOptions={{
headerShown: false,
cardStyleInterpolator: forFade,
}}>
<Stack.Screen name="Notes" component={Home} />
<Stack.Screen
initialParams={{
title: 'Notebooks',
canGoBack: false,
root: true,
}}
name="Notebooks"
component={Folders}
/>
<Stack.Screen name="Favorites" component={Favorites} />
<Stack.Screen name="Trash" component={Trash} />
<Stack.Screen name="NotesPage" component={Notes} />
<Stack.Screen name="Tags" component={Tags} />
<Stack.Screen name="Notebook" component={Notebook} />
<Stack.Screen name="Settings" component={Settings} />
<Stack.Screen name="Search" component={Search} />
</Stack.Navigator>
</NavigationContainer>
</Container>
);
},
() => true,
);