-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
getRootNavigatorScreenOptions.ts
141 lines (119 loc) · 6.1 KB
/
getRootNavigatorScreenOptions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import type {StackCardInterpolationProps, StackNavigationOptions} from '@react-navigation/stack';
import type {ThemeStyles} from '@styles/index';
import type {StyleUtilsType} from '@styles/utils';
import variables from '@styles/variables';
import CONFIG from '@src/CONFIG';
import createModalCardStyleInterpolator from './createModalCardStyleInterpolator';
import getModalPresentationStyle from './getModalPresentationStyle';
type GetOnboardingModalNavigatorOptions = (shouldUseNarrowLayout: boolean) => StackNavigationOptions;
type ScreenOptions = {
rightModalNavigator: StackNavigationOptions;
onboardingModalNavigator: GetOnboardingModalNavigatorOptions;
leftModalNavigator: StackNavigationOptions;
homeScreen: StackNavigationOptions;
fullScreen: StackNavigationOptions;
centralPaneNavigator: StackNavigationOptions;
bottomTab: StackNavigationOptions;
};
const commonScreenOptions: StackNavigationOptions = {
headerShown: false,
gestureDirection: 'horizontal',
animationEnabled: true,
cardOverlayEnabled: true,
animationTypeForReplace: 'push',
};
type GetRootNavigatorScreenOptions = (isSmallScreenWidth: boolean, styles: ThemeStyles, StyleUtils: StyleUtilsType) => ScreenOptions;
const getRootNavigatorScreenOptions: GetRootNavigatorScreenOptions = (isSmallScreenWidth, themeStyles, StyleUtils) => {
const modalCardStyleInterpolator = createModalCardStyleInterpolator(StyleUtils);
return {
rightModalNavigator: {
...commonScreenOptions,
cardStyleInterpolator: (props: StackCardInterpolationProps) => modalCardStyleInterpolator(isSmallScreenWidth, false, false, props),
presentation: getModalPresentationStyle(),
// We want pop in RHP since there are some flows that would work weird otherwise
animationTypeForReplace: 'pop',
cardStyle: {
...StyleUtils.getNavigationModalCardStyle(),
// This is necessary to cover translated sidebar with overlay.
width: isSmallScreenWidth ? '100%' : '200%',
// Excess space should be on the left so we need to position from right.
right: 0,
},
},
onboardingModalNavigator: (shouldUseNarrowLayout: boolean) => ({
cardStyleInterpolator: (props: StackCardInterpolationProps) => modalCardStyleInterpolator(isSmallScreenWidth, false, shouldUseNarrowLayout, props),
headerShown: false,
animationEnabled: true,
cardOverlayEnabled: false,
presentation: 'transparentModal',
cardStyle: {
...StyleUtils.getNavigationModalCardStyle(),
backgroundColor: 'transparent',
width: '100%',
top: 0,
left: 0,
position: 'fixed',
},
}),
leftModalNavigator: {
...commonScreenOptions,
cardStyleInterpolator: (props) => modalCardStyleInterpolator(isSmallScreenWidth, false, false, props),
presentation: getModalPresentationStyle(),
gestureDirection: 'horizontal-inverted',
// We want pop in LHP since there are some flows that would work weird otherwise
animationTypeForReplace: 'pop',
cardStyle: {
...StyleUtils.getNavigationModalCardStyle(),
// This is necessary to cover translated sidebar with overlay.
width: isSmallScreenWidth ? '100%' : '200%',
// LHP should be displayed in place of the sidebar
left: isSmallScreenWidth ? 0 : -variables.sideBarWidth,
},
},
homeScreen: {
title: CONFIG.SITE_TITLE,
...commonScreenOptions,
cardStyleInterpolator: (props: StackCardInterpolationProps) => modalCardStyleInterpolator(isSmallScreenWidth, false, false, props),
cardStyle: {
...StyleUtils.getNavigationModalCardStyle(),
width: isSmallScreenWidth ? '100%' : variables.sideBarWidth,
// We need to shift the sidebar to not be covered by the StackNavigator so it can be clickable.
marginLeft: isSmallScreenWidth ? 0 : -variables.sideBarWidth,
...(isSmallScreenWidth ? {} : themeStyles.borderRight),
},
},
fullScreen: {
...commonScreenOptions,
cardStyleInterpolator: (props: StackCardInterpolationProps) => modalCardStyleInterpolator(isSmallScreenWidth, true, false, props),
cardStyle: {
...StyleUtils.getNavigationModalCardStyle(),
// This is necessary to cover whole screen. Including translated sidebar.
marginLeft: isSmallScreenWidth ? 0 : -variables.sideBarWidth,
},
// We need to turn off animation for the full screen to avoid delay when closing screens.
animationEnabled: isSmallScreenWidth,
},
centralPaneNavigator: {
title: CONFIG.SITE_TITLE,
...commonScreenOptions,
animationEnabled: isSmallScreenWidth,
cardStyleInterpolator: (props: StackCardInterpolationProps) => modalCardStyleInterpolator(isSmallScreenWidth, true, false, props),
cardStyle: {
...StyleUtils.getNavigationModalCardStyle(),
paddingRight: isSmallScreenWidth ? 0 : variables.sideBarWidth,
},
},
bottomTab: {
...commonScreenOptions,
cardStyleInterpolator: (props: StackCardInterpolationProps) => modalCardStyleInterpolator(isSmallScreenWidth, false, false, props),
cardStyle: {
...StyleUtils.getNavigationModalCardStyle(),
width: isSmallScreenWidth ? '100%' : variables.sideBarWidth,
// We need to shift the sidebar to not be covered by the StackNavigator so it can be clickable.
marginLeft: isSmallScreenWidth ? 0 : -variables.sideBarWidth,
...(isSmallScreenWidth ? {} : themeStyles.borderRight),
},
},
};
};
export default getRootNavigatorScreenOptions;