|
1 | 1 | import { ThemedText } from '@/components/ThemedText' |
2 | 2 | import { ThemedView } from '@/components/ThemedView' |
3 | 3 | import { AutoCarousel } from '@strv/react-native-hero-carousel' |
4 | | -import { SafeAreaView } from 'react-native' |
| 4 | +import { SafeAreaView, StyleSheet, Dimensions } from 'react-native' |
| 5 | +import { Image } from 'expo-image' |
| 6 | +import { LinearGradient } from 'expo-linear-gradient' |
| 7 | + |
| 8 | +const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get('window') |
| 9 | + |
| 10 | +const getRandomImageUrl = () => { |
| 11 | + return `https://picsum.photos/${SCREEN_WIDTH}/${SCREEN_HEIGHT}?random=${Math.floor(Math.random() * 1000)}` |
| 12 | +} |
| 13 | + |
| 14 | +const images = Array.from({ length: 5 }, getRandomImageUrl) |
| 15 | + |
5 | 16 | export default function HomeScreen() { |
6 | 17 | return ( |
7 | | - <SafeAreaView style={{ flex: 1 }}> |
8 | | - <ThemedView style={{ flex: 1 }}> |
| 18 | + <SafeAreaView style={styles.container}> |
| 19 | + <ThemedView style={styles.container}> |
9 | 20 | <AutoCarousel> |
10 | | - <ThemedView |
11 | | - style={{ |
12 | | - flex: 1, |
13 | | - backgroundColor: 'red', |
14 | | - maxHeight: 200, |
15 | | - alignItems: 'center', |
16 | | - justifyContent: 'center', |
17 | | - }} |
18 | | - > |
19 | | - <ThemedText type="title">Slide 1</ThemedText> |
20 | | - </ThemedView> |
21 | | - <ThemedView |
22 | | - style={{ |
23 | | - flex: 1, |
24 | | - backgroundColor: 'blue', |
25 | | - maxHeight: 200, |
26 | | - alignItems: 'center', |
27 | | - justifyContent: 'center', |
28 | | - }} |
29 | | - > |
30 | | - <ThemedText type="title">Slide 2</ThemedText> |
31 | | - </ThemedView> |
32 | | - <ThemedView |
33 | | - style={{ |
34 | | - flex: 1, |
35 | | - backgroundColor: 'green', |
36 | | - maxHeight: 200, |
37 | | - alignItems: 'center', |
38 | | - justifyContent: 'center', |
39 | | - }} |
40 | | - > |
41 | | - <ThemedText type="title">Slide 3</ThemedText> |
42 | | - </ThemedView> |
| 21 | + {images.map((image, index) => ( |
| 22 | + <ThemedView key={index} style={styles.slide}> |
| 23 | + <Image source={{ uri: image }} style={styles.image} contentFit="cover" /> |
| 24 | + <LinearGradient colors={['transparent', 'rgba(0,0,0,0.8)']} style={styles.gradient}> |
| 25 | + <ThemedText style={styles.title}>Slide {index + 1}</ThemedText> |
| 26 | + </LinearGradient> |
| 27 | + </ThemedView> |
| 28 | + ))} |
43 | 29 | </AutoCarousel> |
44 | 30 | </ThemedView> |
45 | 31 | </SafeAreaView> |
46 | 32 | ) |
47 | 33 | } |
| 34 | + |
| 35 | +const styles = StyleSheet.create({ |
| 36 | + container: { |
| 37 | + flex: 1, |
| 38 | + }, |
| 39 | + slide: { |
| 40 | + flex: 1, |
| 41 | + width: SCREEN_WIDTH, |
| 42 | + height: SCREEN_HEIGHT * 0.7, |
| 43 | + }, |
| 44 | + image: { |
| 45 | + width: '100%', |
| 46 | + height: '100%', |
| 47 | + }, |
| 48 | + gradient: { |
| 49 | + position: 'absolute', |
| 50 | + bottom: 0, |
| 51 | + left: 0, |
| 52 | + right: 0, |
| 53 | + height: '50%', |
| 54 | + justifyContent: 'flex-end', |
| 55 | + padding: 20, |
| 56 | + }, |
| 57 | + title: { |
| 58 | + fontSize: 32, |
| 59 | + bottom: 100, |
| 60 | + left: 20, |
| 61 | + position: 'absolute', |
| 62 | + lineHeight: 32, |
| 63 | + fontWeight: 'bold', |
| 64 | + color: 'white', |
| 65 | + }, |
| 66 | +}) |
0 commit comments