-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathApp.tsx
More file actions
266 lines (245 loc) · 7.47 KB
/
App.tsx
File metadata and controls
266 lines (245 loc) · 7.47 KB
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
import { enableScreens } from 'react-native-screens';
// run this before any screen render(usually in App.js)
enableScreens();
import * as React from 'react';
import {
StyleSheet,
Text,
ScrollView,
TouchableOpacity,
Button,
Alert,
Platform,
} from 'react-native';
import {
NavigationContainer,
useNavigation,
useNavigationContainerRef,
} from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import JSBottomTabs from './Examples/JSBottomTabs';
import ThreeTabs from './Examples/ThreeTabs';
import FourTabs from './Examples/FourTabs';
import MaterialBottomTabs from './Examples/MaterialBottomTabs';
import SFSymbols from './Examples/SFSymbols';
import LabeledTabs from './Examples/Labeled';
import NativeBottomTabs from './Examples/NativeBottomTabs';
import TintColorsExample from './Examples/TintColors';
import NativeBottomTabsEmbeddedStacks from './Examples/NativeBottomTabsEmbeddedStacks';
import NativeBottomTabsSVGs from './Examples/NativeBottomTabsSVGs';
import NativeBottomTabsRemoteIcons from './Examples/NativeBottomTabsRemoteIcons';
import NativeBottomTabsUnmounting from './Examples/NativeBottomTabsUnmounting';
import NativeBottomTabsCustomTabBar from './Examples/NativeBottomTabsCustomTabBar';
import NativeBottomTabsFreezeOnBlur from './Examples/NativeBottomTabsFreezeOnBlur';
import BottomAccessoryView from './Examples/BottomAccessoryView';
import { useLogger } from '@react-navigation/devtools';
const HiddenTab = () => {
return <FourTabs hideOneTab />;
};
const FourTabsRippleColor = () => {
return <FourTabs rippleColor={'#00ff00'} />;
};
const FourTabsNoAnimations = () => {
return <FourTabs disablePageAnimations />;
};
const FourTabsTransparentScrollEdgeAppearance = () => {
return <FourTabs scrollEdgeAppearance="transparent" />;
};
const FourTabsOpaqueScrollEdgeAppearance = () => {
return <FourTabs scrollEdgeAppearance="opaque" />;
};
const FourTabsWithBackgroundColor = () => {
return <FourTabs backgroundColor={'#87CEEB'} />;
};
const FourTabsTranslucent = () => {
return <FourTabs translucent={false} />;
};
const FourTabsActiveIndicatorColor = () => {
return <FourTabs activeIndicatorColor={'#87CEEB'} />;
};
const UnlabeledTabs = () => {
return <LabeledTabs showLabels={false} />;
};
const examples = [
{
component: ThreeTabs,
name: 'Three Tabs',
},
{ component: FourTabs, name: 'Four Tabs' },
{
component: SFSymbols,
name: 'SF Symbols',
screenOptions: { headerShown: false },
},
{ component: LabeledTabs, name: 'Labeled Tabs' },
{ component: UnlabeledTabs, name: 'Unlabeled Tabs' },
{
component: NativeBottomTabsEmbeddedStacks,
name: 'Embedded stacks',
screenOptions: { headerShown: false },
},
{
component: FourTabsRippleColor,
name: 'Four Tabs with ripple Color',
platform: 'android',
},
{
component: FourTabsNoAnimations,
name: 'Four Tabs - no animations',
},
{
component: FourTabsTransparentScrollEdgeAppearance,
name: 'Four Tabs - Transparent scroll edge appearance',
platform: 'ios',
},
{
component: FourTabsOpaqueScrollEdgeAppearance,
name: 'Four Tabs - Opaque scroll edge appearance',
platform: 'ios',
},
{
component: FourTabsWithBackgroundColor,
name: 'Four Tabs - Custom Background Color of Tabs',
},
{
component: FourTabsTranslucent,
name: 'Four Tabs - Translucent tab bar',
platform: 'android',
},
{
component: FourTabsActiveIndicatorColor,
name: 'Four Tabs - Active Indicator color',
},
{
component: HiddenTab,
name: 'Four Tabs - With Hidden Tab',
},
{
component: NativeBottomTabsFreezeOnBlur,
name: 'Native Bottom Tabs with freezeOnBlur',
},
{
component: NativeBottomTabsSVGs,
name: 'Native Bottom Tabs with SVG Icons',
},
{
component: NativeBottomTabsUnmounting,
name: 'Native Bottom Tabs unmounting',
},
{
component: NativeBottomTabsRemoteIcons,
name: 'Native Bottom Tabs with SVG Remote Icons',
},
{
component: NativeBottomTabsCustomTabBar,
name: 'Native Bottom Tabs with Custom Tab Bar',
},
{ component: NativeBottomTabs, name: 'Native Bottom Tabs' },
{ component: JSBottomTabs, name: 'JS Bottom Tabs' },
{
component: JSBottomTabs,
name: 'JS Bottom Tabs - No header',
screenOptions: { headerShown: false },
},
{ component: MaterialBottomTabs, name: 'Material (JS) Bottom Tabs' },
{ component: TintColorsExample, name: 'Tint Colors' },
{
component: BottomAccessoryView,
name: 'Bottom Accessory View',
screenOptions: { headerShown: false },
},
];
function App() {
const navigation = useNavigation();
return (
<ScrollView>
{examples
.filter((example) =>
'platform' in example ? example?.platform === Platform.OS : example
)
.map((example) => (
<TouchableOpacity
key={example.name}
testID={example.name}
style={styles.exampleTouchable}
onPress={() => {
//@ts-ignore
navigation.navigate(example.name);
}}
>
<Text style={styles.exampleText}>{example.name}</Text>
</TouchableOpacity>
))}
</ScrollView>
);
}
const Stack = createStackNavigator();
const NativeStack = createNativeStackNavigator();
const defaultStack = Platform.OS === 'macos' ? 'js' : 'native';
export default function Navigation() {
const [mode, setMode] = React.useState<'native' | 'js'>(defaultStack);
const NavigationStack = mode === 'js' ? Stack : NativeStack;
const navigationRef = useNavigationContainerRef();
useLogger(navigationRef);
return (
<SafeAreaProvider>
<NavigationContainer ref={navigationRef}>
<NavigationStack.Navigator initialRouteName="BottomTabs Example">
<NavigationStack.Screen
name="BottomTabs Example"
component={App}
options={{
headerRight: () => (
<Button
onPress={() =>
Alert.alert(
'Alert',
`Do you want to change to the ${
mode === 'js' ? 'native stack' : 'js stack'
} ?`,
[
{ text: 'No', onPress: () => {} },
{
text: 'Yes',
onPress: () => {
setMode(mode === 'js' ? 'native' : 'js');
},
},
]
)
}
title={mode === 'js' ? 'JS' : 'NATIVE'}
color="blue"
/>
),
}}
/>
{examples
.filter((example) =>
'platform' in example
? example?.platform === Platform.OS
: example
)
.map((example, index) => (
<NavigationStack.Screen
key={index}
name={example.name}
component={example.component}
options={example.screenOptions}
/>
))}
</NavigationStack.Navigator>
</NavigationContainer>
</SafeAreaProvider>
);
}
const styles = StyleSheet.create({
exampleTouchable: {
padding: 16,
},
exampleText: {
fontSize: 16,
},
});