-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_layout.tsx
203 lines (187 loc) · 5.21 KB
/
_layout.tsx
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import { msg } from '@lingui/macro';
import { type BottomTabBarProps } from '@react-navigation/bottom-tabs';
import { Tabs } from 'expo-router';
import { StyleSheet } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { BottomBar } from '~components/common/custom-bottom-bar/BottomBar';
import StoreReview from '~components/store-review/StoreReview';
import { Icon, Text } from '~components/uikit';
import type { IconName } from '~components/uikit/Icon';
import { useI18n } from '~services/i18n';
import { useTheme } from '~styles';
export type TabList = {
id: string;
title: string;
iconFilled: IconName;
iconOutlined: IconName;
}[];
/**
* _[CUSTOMIZE]_
*
* Determines whether to use a fully customizable bottom tab bar (`CustomBottomBar`)
* or the default tab layout with minimal customization (`DefaultBottomBar`).
*
* Set `USE_CUSTOM_TABS` to `true` if the client requires a highly customizable tab bar (animations, unique styling, etc.).
* Set it to `false` to use the default tab setup, which applies simpler, standard styling.
*
* Example: For a custom bottom bar based on specific branding needs, set `USE_CUSTOM_TABS = true`.
*/
const USE_CUSTOM_TABS = true;
/**
* _[CUSTOMIZE]_
*
* Determines whether to show the store review modal.
*
* The review modal is used to get users feedback about the app.
*
* The idea behind is to get negative feedback before sent to us via email and positive feedback directly in the store.
*/
const USE_STORE_REVIEW = true;
export default function TabsLayout() {
const { _ } = useI18n();
const theme = useTheme();
const tabs: TabList = [
{
id: 'home',
title: _(msg`Home`),
iconFilled: 'homeFilled',
iconOutlined: 'home',
},
{
id: 'search',
title: _(msg`Search`),
iconFilled: 'search',
iconOutlined: 'search',
},
{
id: 'profile',
title: _(msg`Profile`),
iconFilled: 'personCircleFilled',
iconOutlined: 'personCircle',
},
{
id: 'settings',
title: _(msg`Settings`),
iconFilled: 'settingsFilled',
iconOutlined: 'settings',
},
];
return (
<>
{USE_CUSTOM_TABS ? (
<CustomBottomBar tabs={tabs} theme={theme} />
) : (
<DefaultBottomBar tabs={tabs} theme={theme} />
)}
{USE_STORE_REVIEW && <StoreReview />}
</>
);
}
type BottomBarProps = {
tabs: TabList;
theme: ReturnType<typeof useTheme>;
};
function DefaultBottomBar({ tabs, theme }: BottomBarProps) {
const { _ } = useI18n();
const insets = useSafeAreaInsets();
function renderTabIcon({
focused,
iconFilled,
iconOutlined,
}: {
focused: boolean;
iconFilled: IconName;
iconOutlined: IconName;
}) {
return <Icon name={focused ? iconFilled : iconOutlined} color="text" />;
}
function renderBarLabel({
focused,
id,
title,
}: {
focused: boolean;
id: string;
title: string;
}) {
return (
<Text
variant="bodyExtraSmall"
color={focused ? 'text' : 'textMuted'}
testID={id}
>
{title}
</Text>
);
}
return (
<Tabs
initialRouteName="home"
screenOptions={{
headerStyle: {
backgroundColor: theme.colors.surface,
},
headerTintColor: theme.colors.text,
headerBackgroundContainerStyle: {
borderBottomColor: theme.colors.line3,
borderBottomWidth: StyleSheet.hairlineWidth,
},
headerTitleStyle: {
fontSize: theme.fontSizes.bodyBold,
},
tabBarStyle: {
backgroundColor: theme.colors.surface,
borderTopColor: theme.colors.line3,
borderTopWidth: StyleSheet.hairlineWidth,
},
}}
>
{tabs.map(({ id, title, iconFilled, iconOutlined }) => (
<Tabs.Screen
key={title}
name={id}
options={{
title,
tabBarAccessibilityLabel: _(msg`${title} tab`),
tabBarItemStyle: {
// On certain devices without insets, the tab bar is too close to the bottom of the screen
paddingBottom: insets.bottom === 0 ? 4 : 0,
},
tabBarLabel: ({ focused }) =>
renderBarLabel({ focused, id, title }),
tabBarIcon: ({ focused }) =>
renderTabIcon({ focused, iconFilled, iconOutlined }),
}}
/>
))}
</Tabs>
);
}
function renderBottomBar(props: BottomTabBarProps & { tabs: TabList }) {
return <BottomBar {...props} />;
}
function CustomBottomBar({ tabs, theme }: BottomBarProps) {
return (
<Tabs
initialRouteName="home"
tabBar={(props) => renderBottomBar({ ...props, tabs })}
screenOptions={{
headerStyle: {
backgroundColor: theme.colors.surface,
},
headerTintColor: theme.colors.text,
headerBackgroundContainerStyle: {
borderBottomColor: theme.colors.line3,
borderBottomWidth: StyleSheet.hairlineWidth,
},
headerTitleStyle: {
fontSize: theme.fontSizes.bodyBold,
},
}}
>
{tabs.map(({ id, title }) => (
<Tabs.Screen key={title} name={id} options={{ title }} />
))}
</Tabs>
);
}