-
-
Notifications
You must be signed in to change notification settings - Fork 643
Expand file tree
/
Copy pathindex.tsx
More file actions
147 lines (136 loc) · 4.4 KB
/
index.tsx
File metadata and controls
147 lines (136 loc) · 4.4 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
import React from 'react';
import type { ScenarioDescription } from '../../../shared/helpers';
import { createScenario } from '../../../shared/helpers';
import { Button, Text, View } from 'react-native';
import {
type TabRouteConfig,
DEFAULT_TAB_ROUTE_OPTIONS,
useTabsNavigationContext,
TabsContainerWithHostConfigContext,
TabRouteOptions,
} from '../../../../shared/gamma/containers/tabs';
import { CenteredLayoutView } from '../../../../shared/CenteredLayoutView';
import { ToastProvider, useToast } from '../../../../shared/';
import { Colors } from '@apps/shared/styling';
const scenarioDescription: ScenarioDescription = {
name: 'Prevent native selection',
key: 'test-tabs-prevent-native-selection',
details: 'Test preventNativeSelection prop on TabsScreen',
platforms: ['android', 'ios'],
};
function ContentView() {
const nav = useTabsNavigationContext();
const preventNativeSelection =
nav.routeOptions.preventNativeSelection ?? false;
return (
<CenteredLayoutView
testID='tab-bar-prevent-native-selection-view'>
<Text style={{ fontWeight: 'bold', textAlign: 'center' }}
testID='screen-name-label'>
{nav.routeKey}
</Text>
<Text style={{ textAlign: 'center' }}
testID='prevent-native-selection-state'>
preventNativeSelection: {JSON.stringify(preventNativeSelection)}
</Text>
<Button
title="Toggle preventNativeSelection"
onPress={() =>
nav.setRouteOptions(nav.routeKey, {
preventNativeSelection: !preventNativeSelection,
})
}
testID='prevent-native-selection-button'
/>
<TabsNavigationButtons />
</CenteredLayoutView>
);
}
function TabsNavigationButtons() {
const nav = useTabsNavigationContext();
return (
<View>
<Button title="Select First" onPress={() => nav.selectTab('First')} testID='first-button' />
<Button title="Select Second" onPress={() => nav.selectTab('Second')}
testID='second-button' />
<Button title="Select Third" onPress={() => nav.selectTab('Third')}
testID='third-button' />
<Button title="Select Fourth" onPress={() => nav.selectTab('Fourth')}
testID='fourth-button' />
<Button title="Select Fifth" onPress={() => nav.selectTab('Fifth')}
testID='fifth-button' />
<Button title="Select Sixth" onPress={() => nav.selectTab('Sixth')}
testID='sixth-button' />
</View>
);
}
const ROUTE_OPTIONS: TabRouteOptions = {
...DEFAULT_TAB_ROUTE_OPTIONS,
android: {
...DEFAULT_TAB_ROUTE_OPTIONS.android,
standardAppearance: {
// Without 'labeled', Android hides labels on all unselected tabs (auto mode with 6 tabs),
// making it hard to identify tabs when executing the scenario.
tabBarItemLabelVisibilityMode: 'labeled'
},
},
};
const ROUTE_CONFIGS: TabRouteConfig[] = [
{
name: 'First',
Component: ContentView,
options: { ...ROUTE_OPTIONS, title: 'First', tabBarItemTestID: 'First' },
},
{
name: 'Second',
Component: ContentView,
options: { ...ROUTE_OPTIONS, title: 'Second', tabBarItemTestID: 'Second' },
},
{
name: 'Third',
Component: ContentView,
options: { ...ROUTE_OPTIONS, title: 'Third', tabBarItemTestID: 'Third' },
},
{
name: 'Fourth',
Component: ContentView,
options: { ...ROUTE_OPTIONS, title: 'Fourth', tabBarItemTestID: 'Fourth' },
},
{
name: 'Fifth',
Component: ContentView,
options: { ...ROUTE_OPTIONS, title: 'Fifth', tabBarItemTestID: 'Fifth' },
},
{
name: 'Sixth',
Component: ContentView,
options: { ...ROUTE_OPTIONS, title: 'Sixth', tabBarItemTestID: 'Sixth' },
},
];
export function App() {
return (
<ToastProvider>
<AppContents />
</ToastProvider>
);
}
function AppContents() {
const toast = useToast();
return (
<TabsContainerWithHostConfigContext
routeConfigs={ROUTE_CONFIGS}
// 'tabSidebar' enables the sidebar layout on iPad, allowing the iPad-specific
// section of the scenario to be executed.
ios={{ tabBarControllerMode: 'tabSidebar' }}
onTabSelectionPrevented={event => {
const message = `onTabSelectionPrevented: ${event.nativeEvent.preventedScreenKey}`;
console.warn(message);
toast.push({
message: message,
backgroundColor: Colors.GreenLight60,
});
}}
/>
);
}
export default createScenario(App, scenarioDescription);