-
-
Notifications
You must be signed in to change notification settings - Fork 643
Expand file tree
/
Copy pathprevent-native-dismiss-single-stack.tsx
More file actions
149 lines (134 loc) · 3.85 KB
/
prevent-native-dismiss-single-stack.tsx
File metadata and controls
149 lines (134 loc) · 3.85 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
import React from 'react';
import type { ScenarioDescription } from '@apps/tests/shared/helpers';
import { createScenario } from '@apps/tests/shared/helpers';
import { Button, StyleSheet, Text, View } from 'react-native';
import {
StackContainer,
useStackNavigationContext,
} from '@apps/shared/gamma/containers/stack';
import { CenteredLayoutView } from '@apps/shared/CenteredLayoutView';
import { Colors } from '@apps/shared/styling';
import { ToastProvider, useToast } from '@apps/shared';
import { StackNavigationButtons } from '@apps/tests/shared/components/stack-v5/StackNavigationButtons';
const scenarioDescription: ScenarioDescription = {
name: 'Prevent native dismiss - single stack',
key: 'prevent-native-dismiss-single-stack',
details:
'Test prevent native dismiss behavior in simple single-stack scenario',
platforms: ['android'],
};
export function App() {
return (
<ToastProvider>
<StackSetup />
</ToastProvider>
);
}
export function StackSetup() {
const toast = useToast();
return (
<StackContainer
routeConfigs={[
{
name: 'Home',
Component: HomeScreen,
options: {},
},
{
name: 'A',
Component: AScreen,
options: {
headerConfig: {
title: 'A',
},
},
},
{
name: 'B',
Component: BScreen,
options: {
preventNativeDismiss: true,
onNativeDismissPrevented: () => {
console.info('Native dismiss prevented');
toast.push({
message: 'Native dismiss prevented',
backgroundColor: Colors.GreenLight60,
});
},
headerConfig: {
title: 'B',
},
},
},
]}
/>
);
}
export function HomeScreen() {
return (
<CenteredLayoutView style={{ backgroundColor: Colors.BlueLight40 }}>
<RouteInformation routeName="Home" />
<StackNavigationButtons isPopEnabled={false} routeNames={['A', 'B']} />
</CenteredLayoutView>
);
}
export function AScreen() {
return (
<CenteredLayoutView style={{ backgroundColor: Colors.YellowLight40 }}>
<RouteInformation routeName="A" />
<PreventNativeDismissInfo />
<StackNavigationButtons isPopEnabled={true} routeNames={['A', 'B']} />
</CenteredLayoutView>
);
}
export function BScreen() {
return (
<CenteredLayoutView style={{ backgroundColor: Colors.GreenLight100 }}>
<RouteInformation routeName="B" />
<PreventNativeDismissInfo />
<StackNavigationButtons isPopEnabled={true} routeNames={['A', 'B']} />
<TogglePreventNativeDismiss />
</CenteredLayoutView>
);
}
export function RouteInformation(props: { routeName: string }) {
const routeKey = useStackNavigationContext().routeKey;
return (
<View>
<Text style={styles.routeInformation}>Name: {props.routeName}</Text>
<Text style={styles.routeInformation}>Key: {routeKey}</Text>
</View>
);
}
export function TogglePreventNativeDismiss() {
const navigation = useStackNavigationContext();
return (
<Button
title="Toggle Prevent Native Dismiss"
onPress={() =>
navigation.setRouteOptions(navigation.routeKey, {
preventNativeDismiss: !navigation.routeOptions.preventNativeDismiss,
})
}
/>
);
}
export function PreventNativeDismissInfo() {
const navContext = useStackNavigationContext();
return (
<View>
<Text style={styles.routeInformation}>
Prevent native dismiss:{' '}
{navContext.routeOptions.preventNativeDismiss ? 'Enabled' : 'Disabled'}
</Text>
</View>
);
}
const styles = StyleSheet.create({
routeInformation: {
color: 'black',
fontSize: 20,
fontWeight: 'bold',
},
});
export default createScenario(App, scenarioDescription);