-
-
Notifications
You must be signed in to change notification settings - Fork 644
Expand file tree
/
Copy pathTest2543.tsx
More file actions
149 lines (141 loc) · 3.79 KB
/
Test2543.tsx
File metadata and controls
149 lines (141 loc) · 3.79 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 {
NavigationContainer,
ParamListBase,
RouteProp,
} from '@react-navigation/native';
import {
NativeStackNavigationOptions,
NativeStackNavigationProp,
createNativeStackNavigator,
} from '@react-navigation/native-stack';
import { Button, Text, View } from 'react-native';
import { Colors } from '@apps/shared/styling';
const FORM_SHEET_CONFIGURATIONS: Record<string, NativeStackNavigationOptions> =
{
TwoDetentsInitialFirst: {
sheetAllowedDetents: [0.3, 0.55],
},
TwoDetentsInitialSecond: {
sheetAllowedDetents: [0.3, 0.55],
sheetInitialDetentIndex: 1,
},
ThreeDetentsInitialFirst: {
sheetAllowedDetents: [0.3, 0.55, 0.8],
},
ThreeDetentsInitialSecond: {
sheetAllowedDetents: [0.3, 0.55, 0.8],
sheetInitialDetentIndex: 1,
},
ThreeDetentsInitialThird: {
sheetAllowedDetents: [0.3, 0.55, 0.8],
sheetInitialDetentIndex: 2,
},
};
type StackRouteParamList = {
Home: undefined;
} & {
[P in keyof typeof FORM_SHEET_CONFIGURATIONS]: undefined;
};
type NavigationProp<ParamList extends ParamListBase> = {
navigation: NativeStackNavigationProp<ParamList>;
route: RouteProp<ParamList>;
};
type StackNavigationProp = NavigationProp<StackRouteParamList>;
const Stack = createNativeStackNavigator<StackRouteParamList>();
function Home({ navigation }: StackNavigationProp) {
return (
<View
style={{
backgroundColor: Colors.GreenLight40,
flex: 1,
justifyContent: 'center',
alignItems: 'center',
gap: 15,
}}>
{Object.keys(FORM_SHEET_CONFIGURATIONS).map(key => (
<Button
title={key}
key={key}
onPress={() => navigation.navigate(key)}
testID={`home-button-open-${key}`}
/>
))}
</View>
);
}
function FormSheet({ route }: StackNavigationProp) {
return (
<View style={{ paddingTop: 20 }}>
<Text
style={{
fontSize: 24,
fontWeight: 'bold',
marginBottom: 16,
textAlign: 'center',
}}
testID={`${route.name}-text-header`}>
{route.name}
</Text>
<Text style={{ textAlign: 'center', marginBottom: 16 }}>
You should be able to easily switch between detents.
</Text>
<View
style={{
alignItems: 'center',
justifyContent: 'center',
height: 180,
}}>
<Text testID={`${route.name}-text-first-detent`}>
This should be visible on first detent.
</Text>
</View>
<View
style={{
alignItems: 'center',
justifyContent: 'center',
height: 180,
backgroundColor: Colors.PurpleLight40,
}}>
<Text testID={`${route.name}-text-second-detent`}>
This should be visible on second detent.
</Text>
</View>
<View
style={{
alignItems: 'center',
justifyContent: 'center',
height: 200,
backgroundColor: Colors.NavyLight40,
}}>
<Text testID={`${route.name}-text-third-detent`}>
This should be visible on third detent.
</Text>
</View>
</View>
);
}
export default function App() {
return (
<NavigationContainer>
<Stack.Navigator
screenOptions={{
headerShown: false,
}}>
<Stack.Screen name="Home" component={Home} />
{Object.keys(FORM_SHEET_CONFIGURATIONS).map(key => (
<Stack.Screen
name={key}
key={key}
component={FormSheet}
options={{
presentation: 'formSheet',
sheetGrabberVisible: true,
...FORM_SHEET_CONFIGURATIONS[key],
}}
/>
))}
</Stack.Navigator>
</NavigationContainer>
);
}