-
-
Notifications
You must be signed in to change notification settings - Fork 643
Expand file tree
/
Copy pathindex.tsx
More file actions
122 lines (112 loc) · 2.97 KB
/
index.tsx
File metadata and controls
122 lines (112 loc) · 2.97 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
import React, { useCallback, useMemo } from 'react';
import { StyleSheet, Text } from 'react-native';
import type { ScenarioDescription } from '@apps/tests/shared/helpers';
import { createScenario } from '@apps/tests/shared/helpers';
import {
TabsContainer,
type TabRouteConfig,
DEFAULT_TAB_ROUTE_OPTIONS,
useTabsNavigationContext,
} from '@apps/shared/gamma/containers/tabs';
import { CenteredLayoutView } from '@apps/shared/CenteredLayoutView';
import { ToastProvider, useToast } from '@apps/shared/';
import { Colors } from '@apps/shared/styling';
const scenarioDescription: ScenarioDescription = {
name: 'Tabs lifecycle events',
key: 'test-tabs-events',
details:
'Verify lifecycle events (onWillAppear, etc.) fire on tab switch',
platforms: ['ios', 'android'],
};
function TabScreen() {
const { routeKey } = useTabsNavigationContext();
return (
<CenteredLayoutView testID={`tabContent-${routeKey}`}>
<Text style={styles.tabLabel} testID={`tabLabel-${routeKey}`}>
{routeKey}
</Text>
<Text style={styles.tabHint}>Switch tabs to trigger lifecycle events</Text>
</CenteredLayoutView>
);
}
function AppContents() {
const toast = useToast();
const makeCallbacks = useCallback(
(tabName: string) => ({
onWillAppear: () =>
toast.push({
message: `${tabName}: onWillAppear`,
backgroundColor: Colors.GreenLight100,
}),
onDidAppear: () =>
toast.push({
message: `${tabName}: onDidAppear`,
backgroundColor: Colors.BlueLight100,
}),
onWillDisappear: () =>
toast.push({
message: `${tabName}: onWillDisappear`,
backgroundColor: Colors.NavyLight60,
}),
onDidDisappear: () =>
toast.push({
message: `${tabName}: onDidDisappear`,
backgroundColor: Colors.NavyLight100,
}),
}),
[toast],
);
const TAB_CONFIGS = useMemo<TabRouteConfig[]>(
() => [
{
name: 'TabA',
Component: TabScreen,
options: {
...DEFAULT_TAB_ROUTE_OPTIONS,
title: 'Tab A',
...makeCallbacks('TabA'),
},
},
{
name: 'TabB',
Component: TabScreen,
options: {
...DEFAULT_TAB_ROUTE_OPTIONS,
title: 'Tab B',
...makeCallbacks('TabB'),
},
},
{
name: 'TabC',
Component: TabScreen,
options: {
...DEFAULT_TAB_ROUTE_OPTIONS,
title: 'Tab C',
...makeCallbacks('TabC'),
},
},
],
[makeCallbacks],
);
return <TabsContainer routeConfigs={TAB_CONFIGS} />;
}
export function App() {
return (
<ToastProvider>
<AppContents />
</ToastProvider>
);
}
export default createScenario(App, scenarioDescription);
const styles = StyleSheet.create({
tabLabel: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 8,
},
tabHint: {
color: '#666',
fontSize: 13,
textAlign: 'center',
},
});