|
| 1 | +import React, { useMemo, useRef } from 'react'; |
| 2 | + |
| 3 | +import { Platform, ScrollView, StyleSheet, View } from 'react-native'; |
| 4 | + |
| 5 | +import { |
| 6 | + type EdgeInsets, |
| 7 | + useSafeAreaInsets, |
| 8 | +} from 'react-native-safe-area-context'; |
| 9 | + |
| 10 | +import MapWrapper from '@src/components/MapWrapper'; |
| 11 | +import { useAppTheme } from '@src/hooks/useAppTheme'; |
| 12 | +import type { AppTheme } from '@src/theme'; |
| 13 | + |
| 14 | +import type { |
| 15 | + GoogleMapsViewRef, |
| 16 | + RNLatLng, |
| 17 | +} from 'react-native-google-maps-plus'; |
| 18 | + |
| 19 | +const LOCATIONS: RNLatLng[] = [ |
| 20 | + { latitude: 37.7749, longitude: -122.4194 }, // San Francisco |
| 21 | + { latitude: 40.7128, longitude: -74.006 }, // New York City |
| 22 | + { latitude: 52.52, longitude: 13.405 }, // Berlin |
| 23 | + { latitude: 48.8566, longitude: 2.3522 }, // Paris |
| 24 | + { latitude: 35.6762, longitude: 139.6503 }, // Tokyo |
| 25 | + { latitude: -33.8688, longitude: 151.2093 }, // Sydney |
| 26 | + { latitude: 51.5074, longitude: -0.1278 }, // London |
| 27 | + { latitude: 55.7558, longitude: 37.6173 }, // Moscow |
| 28 | + { latitude: 19.4326, longitude: -99.1332 }, // Mexico City |
| 29 | + { latitude: -23.5505, longitude: -46.6333 }, // São Paulo |
| 30 | +]; |
| 31 | + |
| 32 | +export default function ScrollViewScreen() { |
| 33 | + const theme = useAppTheme(); |
| 34 | + const layout = useSafeAreaInsets(); |
| 35 | + const styles = useMemo(() => getThemedStyles(theme, layout), [theme, layout]); |
| 36 | + const mapRef = useRef<GoogleMapsViewRef | null>(null); |
| 37 | + |
| 38 | + return ( |
| 39 | + <ScrollView |
| 40 | + style={styles.scrollView} |
| 41 | + contentContainerStyle={styles.content} |
| 42 | + > |
| 43 | + {LOCATIONS.map((center, i) => { |
| 44 | + const isLite = i % 2 !== 0; |
| 45 | + return ( |
| 46 | + <View key={i} style={styles.card}> |
| 47 | + <MapWrapper |
| 48 | + mapRef={mapRef} |
| 49 | + style={styles.map} |
| 50 | + initialProps={{ |
| 51 | + camera: { center, zoom: 12 }, |
| 52 | + liteMode: isLite, |
| 53 | + }} |
| 54 | + uiSettings={ |
| 55 | + isLite && Platform.OS === 'ios' |
| 56 | + ? { |
| 57 | + allGesturesEnabled: false, |
| 58 | + compassEnabled: false, |
| 59 | + rotateEnabled: false, |
| 60 | + scrollEnabled: false, |
| 61 | + scrollDuringRotateOrZoomEnabled: false, |
| 62 | + tiltEnabled: false, |
| 63 | + zoomGesturesEnabled: false, |
| 64 | + } |
| 65 | + : undefined |
| 66 | + } |
| 67 | + mapPadding={{ top: 0, bottom: 0, right: 0, left: 0 }} |
| 68 | + /> |
| 69 | + </View> |
| 70 | + ); |
| 71 | + })} |
| 72 | + </ScrollView> |
| 73 | + ); |
| 74 | +} |
| 75 | + |
| 76 | +const getThemedStyles = (theme: AppTheme, layout: EdgeInsets) => |
| 77 | + StyleSheet.create({ |
| 78 | + scrollView: { |
| 79 | + flex: 1, |
| 80 | + backgroundColor: theme.bgPrimary, |
| 81 | + }, |
| 82 | + content: { |
| 83 | + padding: 16, |
| 84 | + paddingBottom: layout.bottom + 24, |
| 85 | + gap: 20, |
| 86 | + }, |
| 87 | + card: { |
| 88 | + borderRadius: 10, |
| 89 | + overflow: 'hidden', |
| 90 | + backgroundColor: theme.bgHeader, |
| 91 | + shadowColor: theme.shadow, |
| 92 | + shadowOffset: { width: 0, height: 2 }, |
| 93 | + shadowOpacity: 0.25, |
| 94 | + shadowRadius: 4, |
| 95 | + elevation: 2, |
| 96 | + }, |
| 97 | + map: { |
| 98 | + height: 250, |
| 99 | + }, |
| 100 | + }); |
0 commit comments