Skip to content

Commit bda8134

Browse files
committed
Add example
1 parent fbcc673 commit bda8134

File tree

2 files changed

+170
-0
lines changed

2 files changed

+170
-0
lines changed

apps/src/tests/Test3248.tsx

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
import React from 'react';
2+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
3+
import type {
4+
NativeStackNavigationOptions,
5+
NativeStackNavigationProp,
6+
} from '@react-navigation/native-stack';
7+
import { NavigationContainer } from '@react-navigation/native';
8+
import { Button, TextInput, View } from 'react-native';
9+
10+
type StackParamList = {
11+
Main: undefined;
12+
FormSheetWithFitToContents: undefined;
13+
FormSheetWithSmallDetent: undefined;
14+
FormSheetWithMediumDetent: undefined;
15+
FormSheetWithLargeDetent: undefined;
16+
FormSheetWithTwoDetents: undefined;
17+
FormSheetWithThreeDetents: undefined;
18+
FormSheetWithAutoFocusAndFitToContents: undefined;
19+
FormSheetWithAutoFocusAndDetent: undefined;
20+
};
21+
22+
type MainProps = {
23+
navigation: NativeStackNavigationProp<StackParamList, 'Main'>;
24+
};
25+
26+
const Stack = createNativeStackNavigator();
27+
28+
const Main = ({ navigation }: MainProps) => {
29+
return (
30+
<View style={{ flex: 1 }}>
31+
<Button
32+
title="Fit to contents"
33+
onPress={() => navigation.navigate('FormSheetWithFitToContents')}
34+
/>
35+
<Button
36+
title="1 small detent"
37+
onPress={() => navigation.navigate('FormSheetWithSmallDetent')}
38+
/>
39+
<Button
40+
title="1 medium detent"
41+
onPress={() => navigation.navigate('FormSheetWithMediumDetent')}
42+
/>
43+
<Button
44+
title="1 large detent"
45+
onPress={() => navigation.navigate('FormSheetWithLargeDetent')}
46+
/>
47+
<Button
48+
title="2 detents"
49+
onPress={() => navigation.navigate('FormSheetWithTwoDetents')}
50+
/>
51+
<Button
52+
title="3 detents"
53+
onPress={() => navigation.navigate('FormSheetWithThreeDetents')}
54+
/>
55+
<Button
56+
title="Fit to contents - autoFocus"
57+
onPress={() =>
58+
navigation.navigate('FormSheetWithAutoFocusAndFitToContents')
59+
}
60+
/>
61+
<Button
62+
title="1 detent - autoFocus"
63+
onPress={() => navigation.navigate('FormSheetWithAutoFocusAndDetent')}
64+
/>
65+
</View>
66+
);
67+
};
68+
69+
const formSheetBaseOptions: NativeStackNavigationOptions = {
70+
presentation: 'formSheet',
71+
animation: 'slide_from_bottom',
72+
headerShown: false,
73+
};
74+
75+
const FormSheetBase = ({ autoFocus = false }: { autoFocus?: boolean }) => {
76+
return (
77+
<View>
78+
<TextInput
79+
autoFocus={autoFocus}
80+
style={{
81+
borderWidth: 1,
82+
borderColor: 'black',
83+
padding: 10,
84+
borderRadius: 10,
85+
}}
86+
/>
87+
</View>
88+
);
89+
};
90+
91+
const FormSheetWithAutoFocus = () => <FormSheetBase autoFocus />;
92+
93+
export default function App() {
94+
return (
95+
<NavigationContainer>
96+
<Stack.Navigator>
97+
<Stack.Screen
98+
component={Main}
99+
name="main"
100+
options={{ title: 'Main' }}
101+
/>
102+
<Stack.Screen
103+
component={FormSheetBase}
104+
name="FormSheetWithFitToContents"
105+
options={{
106+
...formSheetBaseOptions,
107+
sheetAllowedDetents: 'fitToContents',
108+
}}
109+
/>
110+
<Stack.Screen
111+
component={FormSheetBase}
112+
name="FormSheetWithSmallDetent"
113+
options={{
114+
...formSheetBaseOptions,
115+
sheetAllowedDetents: [0.1],
116+
}}
117+
/>
118+
<Stack.Screen
119+
component={FormSheetBase}
120+
name="FormSheetWithMediumDetent"
121+
options={{
122+
...formSheetBaseOptions,
123+
sheetAllowedDetents: [0.5],
124+
}}
125+
/>
126+
<Stack.Screen
127+
component={FormSheetBase}
128+
name="FormSheetWithLargeDetent"
129+
options={{
130+
...formSheetBaseOptions,
131+
sheetAllowedDetents: [0.8],
132+
}}
133+
/>
134+
<Stack.Screen
135+
component={FormSheetBase}
136+
name="FormSheetWithTwoDetents"
137+
options={{
138+
...formSheetBaseOptions,
139+
sheetAllowedDetents: [0.3, 0.6],
140+
}}
141+
/>
142+
<Stack.Screen
143+
component={FormSheetBase}
144+
name="FormSheetWithThreeDetents"
145+
options={{
146+
...formSheetBaseOptions,
147+
sheetAllowedDetents: [0.3, 0.6, 0.9],
148+
}}
149+
/>
150+
<Stack.Screen
151+
component={FormSheetWithAutoFocus}
152+
name="FormSheetWithAutoFocusAndFitToContents"
153+
options={{
154+
...formSheetBaseOptions,
155+
sheetAllowedDetents: 'fitToContents',
156+
}}
157+
/>
158+
<Stack.Screen
159+
component={FormSheetWithAutoFocus}
160+
name="FormSheetWithAutoFocusAndDetent"
161+
options={{
162+
...formSheetBaseOptions,
163+
sheetAllowedDetents: [0.5],
164+
}}
165+
/>
166+
</Stack.Navigator>
167+
</NavigationContainer>
168+
);
169+
}

apps/src/tests/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export { default as Test3115 } from './Test3115';
150150
export { default as Test3168 } from './Test3168';
151151
export { default as Test3173 } from './Test3173';
152152
export { default as Test3239 } from './Test3239';
153+
export { default as Test3248 } from './Test3248';
153154
export { default as TestScreenAnimation } from './TestScreenAnimation';
154155
export { default as TestScreenAnimationV5 } from './TestScreenAnimationV5';
155156
export { default as TestHeader } from './TestHeader';

0 commit comments

Comments
 (0)