|
| 1 | +import React from 'react'; |
| 2 | +import { NavigationContainer, ParamListBase } from '@react-navigation/native'; |
| 3 | +import { |
| 4 | + NativeStackNavigationProp, |
| 5 | + createNativeStackNavigator, |
| 6 | +} from '@react-navigation/native-stack'; |
| 7 | +import { Button, View, Text, ScrollView } from 'react-native'; |
| 8 | +import PressableWithFeedback from '../shared/PressableWithFeedback'; |
| 9 | + |
| 10 | +type RouteParamList = { |
| 11 | + Main: undefined; |
| 12 | + PushWithoutHeader: undefined; |
| 13 | + PushWithTransparentHeader: undefined; |
| 14 | + ModalWithView: undefined; |
| 15 | + ModalWithViewAndNoHeader: undefined; |
| 16 | + ModalWithViewAndTransparentHeader: undefined; |
| 17 | + ModalWithScrollView: undefined; |
| 18 | + ModalWithScrollViewAndNoHeader: undefined; |
| 19 | + ModalWithScrollViewAndTransparentHeader: undefined; |
| 20 | + ModalWithScrollViewBehaviorAutomatic: undefined; |
| 21 | + ModalWithScrollViewBehaviorAutomaticAndNoHeader: undefined; |
| 22 | + ModalWithScrollViewBehaviorAutomaticAndTransparentHeader: undefined; |
| 23 | +}; |
| 24 | + |
| 25 | +type NavigationProp<ParamList extends ParamListBase> = { |
| 26 | + navigation: NativeStackNavigationProp<ParamList>; |
| 27 | +}; |
| 28 | + |
| 29 | +type StackNavigationProp = NavigationProp<RouteParamList>; |
| 30 | + |
| 31 | +const Stack = createNativeStackNavigator<RouteParamList>(); |
| 32 | + |
| 33 | +function Screen1({ navigation }: StackNavigationProp) { |
| 34 | + return ( |
| 35 | + <View style={{ padding: 10 }}> |
| 36 | + <Text style={{ fontSize: 30, fontWeight: 'bold' }}>Push</Text> |
| 37 | + <Button |
| 38 | + title="WithoutHeader" |
| 39 | + onPress={() => navigation.push('PushWithoutHeader')} |
| 40 | + /> |
| 41 | + <Button |
| 42 | + title="TransparentHeader" |
| 43 | + onPress={() => navigation.push('PushWithTransparentHeader')} |
| 44 | + /> |
| 45 | + <Text style={{ fontSize: 30, fontWeight: 'bold', marginTop: 10 }}> |
| 46 | + Modal + View |
| 47 | + </Text> |
| 48 | + <Button title="Normal" onPress={() => navigation.push('ModalWithView')} /> |
| 49 | + <Button |
| 50 | + title="WithoutHeader" |
| 51 | + onPress={() => navigation.push('ModalWithViewAndNoHeader')} |
| 52 | + /> |
| 53 | + <Button |
| 54 | + title="TransparentHeader" |
| 55 | + onPress={() => navigation.push('ModalWithViewAndTransparentHeader')} |
| 56 | + /> |
| 57 | + <Text style={{ fontSize: 30, fontWeight: 'bold', marginTop: 10 }}> |
| 58 | + Modal + ScrollView |
| 59 | + </Text> |
| 60 | + <Button |
| 61 | + title="Normal" |
| 62 | + onPress={() => navigation.push('ModalWithScrollView')} |
| 63 | + /> |
| 64 | + <Button |
| 65 | + title="WithoutHeader" |
| 66 | + onPress={() => navigation.push('ModalWithScrollViewAndNoHeader')} |
| 67 | + /> |
| 68 | + <Button |
| 69 | + title="TransparentHeader" |
| 70 | + onPress={() => |
| 71 | + navigation.push('ModalWithScrollViewAndTransparentHeader') |
| 72 | + } |
| 73 | + /> |
| 74 | + <Text style={{ fontSize: 30, fontWeight: 'bold', marginTop: 10 }}> |
| 75 | + Modal + ScrollView |
| 76 | + </Text> |
| 77 | + <Text style={{ fontStyle: 'italic' }}> |
| 78 | + with contentInsetAdjustmentBehavior='automatic' |
| 79 | + </Text> |
| 80 | + <Button |
| 81 | + title="Normal" |
| 82 | + onPress={() => navigation.push('ModalWithScrollViewBehaviorAutomatic')} |
| 83 | + /> |
| 84 | + <Button |
| 85 | + title="WithoutHeader" |
| 86 | + onPress={() => |
| 87 | + navigation.push('ModalWithScrollViewBehaviorAutomaticAndNoHeader') |
| 88 | + } |
| 89 | + /> |
| 90 | + <Button |
| 91 | + title="TransparentHeader" |
| 92 | + onPress={() => |
| 93 | + navigation.push( |
| 94 | + 'ModalWithScrollViewBehaviorAutomaticAndTransparentHeader', |
| 95 | + ) |
| 96 | + } |
| 97 | + /> |
| 98 | + </View> |
| 99 | + ); |
| 100 | +} |
| 101 | + |
| 102 | +function Screen2() { |
| 103 | + return ( |
| 104 | + <View style={{ gap: 20, paddingHorizontal: 30, paddingVertical: 10 }}> |
| 105 | + {[...Array(30).keys()].map(index => ( |
| 106 | + <PressableWithFeedback |
| 107 | + key={index + 1} |
| 108 | + onPress={() => console.log(`Pressed #${index + 1}`)} |
| 109 | + style={{ |
| 110 | + paddingVertical: 10, |
| 111 | + paddingHorizontal: 20, |
| 112 | + }}> |
| 113 | + <Text>Pressable #{index + 1}</Text> |
| 114 | + </PressableWithFeedback> |
| 115 | + ))} |
| 116 | + </View> |
| 117 | + ); |
| 118 | +} |
| 119 | + |
| 120 | +function Screen3() { |
| 121 | + return ( |
| 122 | + <ScrollView |
| 123 | + contentContainerStyle={{ |
| 124 | + gap: 20, |
| 125 | + paddingHorizontal: 30, |
| 126 | + paddingVertical: 10, |
| 127 | + }}> |
| 128 | + {[...Array(30).keys()].map(index => ( |
| 129 | + <PressableWithFeedback |
| 130 | + key={index + 1} |
| 131 | + onPress={() => console.log(`Pressed #${index + 1}`)} |
| 132 | + style={{ |
| 133 | + paddingVertical: 10, |
| 134 | + paddingHorizontal: 20, |
| 135 | + }}> |
| 136 | + <Text>Pressable #{index + 1}</Text> |
| 137 | + </PressableWithFeedback> |
| 138 | + ))} |
| 139 | + </ScrollView> |
| 140 | + ); |
| 141 | +} |
| 142 | + |
| 143 | +function Screen4() { |
| 144 | + return ( |
| 145 | + <ScrollView |
| 146 | + contentInsetAdjustmentBehavior="automatic" |
| 147 | + contentContainerStyle={{ |
| 148 | + gap: 20, |
| 149 | + paddingHorizontal: 30, |
| 150 | + paddingVertical: 10, |
| 151 | + }}> |
| 152 | + {[...Array(30).keys()].map(index => ( |
| 153 | + <PressableWithFeedback |
| 154 | + key={index + 1} |
| 155 | + onPress={() => console.log(`Pressed #${index + 1}`)} |
| 156 | + style={{ |
| 157 | + paddingVertical: 10, |
| 158 | + paddingHorizontal: 20, |
| 159 | + }}> |
| 160 | + <Text>Pressable #{index + 1}</Text> |
| 161 | + </PressableWithFeedback> |
| 162 | + ))} |
| 163 | + </ScrollView> |
| 164 | + ); |
| 165 | +} |
| 166 | + |
| 167 | +export default function App() { |
| 168 | + return ( |
| 169 | + <NavigationContainer> |
| 170 | + <Stack.Navigator |
| 171 | + screenOptions={{ |
| 172 | + headerRight: () => ( |
| 173 | + <PressableWithFeedback |
| 174 | + onPress={() => console.log('Pressed headerRight')}> |
| 175 | + <Text>Pressable</Text> |
| 176 | + </PressableWithFeedback> |
| 177 | + ), |
| 178 | + }}> |
| 179 | + <Stack.Screen name="Main" component={Screen1} /> |
| 180 | + <Stack.Screen |
| 181 | + name="PushWithoutHeader" |
| 182 | + component={Screen2} |
| 183 | + options={{ |
| 184 | + headerShown: false, |
| 185 | + }} |
| 186 | + /> |
| 187 | + <Stack.Screen |
| 188 | + name="PushWithTransparentHeader" |
| 189 | + component={Screen2} |
| 190 | + options={{ |
| 191 | + headerTransparent: true, |
| 192 | + }} |
| 193 | + /> |
| 194 | + <Stack.Screen |
| 195 | + name="ModalWithView" |
| 196 | + component={Screen2} |
| 197 | + options={{ |
| 198 | + presentation: 'modal', |
| 199 | + }} |
| 200 | + /> |
| 201 | + <Stack.Screen |
| 202 | + name="ModalWithViewAndNoHeader" |
| 203 | + component={Screen2} |
| 204 | + options={{ |
| 205 | + presentation: 'modal', |
| 206 | + headerShown: false, |
| 207 | + }} |
| 208 | + /> |
| 209 | + <Stack.Screen |
| 210 | + name="ModalWithViewAndTransparentHeader" |
| 211 | + component={Screen2} |
| 212 | + options={{ |
| 213 | + presentation: 'modal', |
| 214 | + headerTransparent: true, |
| 215 | + }} |
| 216 | + /> |
| 217 | + <Stack.Screen |
| 218 | + name="ModalWithScrollView" |
| 219 | + component={Screen3} |
| 220 | + options={{ |
| 221 | + presentation: 'modal', |
| 222 | + }} |
| 223 | + /> |
| 224 | + <Stack.Screen |
| 225 | + name="ModalWithScrollViewAndNoHeader" |
| 226 | + component={Screen3} |
| 227 | + options={{ |
| 228 | + presentation: 'modal', |
| 229 | + headerShown: false, |
| 230 | + }} |
| 231 | + /> |
| 232 | + <Stack.Screen |
| 233 | + name="ModalWithScrollViewAndTransparentHeader" |
| 234 | + component={Screen3} |
| 235 | + options={{ |
| 236 | + presentation: 'modal', |
| 237 | + headerTransparent: true, |
| 238 | + }} |
| 239 | + /> |
| 240 | + <Stack.Screen |
| 241 | + name="ModalWithScrollViewBehaviorAutomatic" |
| 242 | + component={Screen4} |
| 243 | + options={{ |
| 244 | + presentation: 'modal', |
| 245 | + }} |
| 246 | + /> |
| 247 | + <Stack.Screen |
| 248 | + name="ModalWithScrollViewBehaviorAutomaticAndNoHeader" |
| 249 | + component={Screen4} |
| 250 | + options={{ |
| 251 | + presentation: 'modal', |
| 252 | + headerShown: false, |
| 253 | + }} |
| 254 | + /> |
| 255 | + <Stack.Screen |
| 256 | + name="ModalWithScrollViewBehaviorAutomaticAndTransparentHeader" |
| 257 | + component={Screen4} |
| 258 | + options={{ |
| 259 | + presentation: 'modal', |
| 260 | + headerTransparent: true, |
| 261 | + }} |
| 262 | + /> |
| 263 | + </Stack.Navigator> |
| 264 | + </NavigationContainer> |
| 265 | + ); |
| 266 | +} |
0 commit comments