-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnteringAnimationExample.tsx
More file actions
121 lines (111 loc) · 3.34 KB
/
EnteringAnimationExample.tsx
File metadata and controls
121 lines (111 loc) · 3.34 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
import { HeroCarousel } from '@strv/react-native-hero-carousel'
import { SafeAreaView, StyleSheet, View, Text, Dimensions } from 'react-native'
import { Image } from 'expo-image'
import { LinearGradient } from 'expo-linear-gradient'
import { FadeIn, SlideInDown, SlideInRight, ZoomIn, FlipInEasyX } from 'react-native-reanimated'
import { useEffect } from 'react'
const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get('window')
const getRandomImageUrl = () => {
return `https://picsum.photos/${SCREEN_WIDTH}/${SCREEN_HEIGHT}?random=${Math.floor(Math.random() * 1000)}`
}
const images = Array.from({ length: 5 }, getRandomImageUrl)
const animationNames = ['FadeIn', 'SlideInDown', 'SlideInRight', 'ZoomIn', 'FlipInEasyX']
const Slide = ({ image, title, index }: { image: string; title: string; index: number }) => {
// Different animation types for each slide to showcase variety
const animationConfigs = [
{ entering: FadeIn.duration(400) },
{ entering: SlideInDown.duration(500) },
{ entering: SlideInRight.duration(600) },
{ entering: ZoomIn.duration(700) },
{ entering: FlipInEasyX.duration(800) },
]
const animationConfig = animationConfigs[index % animationConfigs.length]
return (
<View key={index} style={styles.slide}>
<Image source={{ uri: image }} style={styles.image} contentFit="cover" transition={200} />
<LinearGradient colors={['transparent', 'rgba(0,0,0,0.8)']} style={styles.gradient}>
<View style={styles.text}>
<HeroCarousel.AnimatedView style={styles.textContainer} {...animationConfig}>
<Text style={styles.title}>{title}</Text>
</HeroCarousel.AnimatedView>
<HeroCarousel.AnimatedView
style={styles.textContainer}
entering={FadeIn.duration(400).delay(200)}
>
<Text style={styles.subtitle}>
Animation: {animationNames[index % animationNames.length]}
</Text>
</HeroCarousel.AnimatedView>
</View>
</LinearGradient>
</View>
)
}
export default function EnteringAnimationExample() {
// Preload all images when component mounts
useEffect(() => {
Image.prefetch(images)
}, [])
return (
<HeroCarousel.Provider>
<SafeAreaView style={styles.container}>
<View style={styles.container}>
<HeroCarousel>
{images.map((image, index) => (
<Slide key={index} image={image} title={`Slide ${index + 1}`} index={index} />
))}
</HeroCarousel>
</View>
</SafeAreaView>
</HeroCarousel.Provider>
)
}
const styles = StyleSheet.create({
textContainer: {
flex: 1,
},
container: {
flex: 1,
backgroundColor: '#fff',
},
slide: {
flex: 1,
width: '100%',
height: '100%',
overflow: 'hidden',
backgroundColor: 'black',
},
image: {
width: '100%',
height: '100%',
transformOrigin: 'center',
},
gradient: {
position: 'absolute',
bottom: 0,
left: 0,
right: 0,
height: '50%',
justifyContent: 'flex-end',
padding: 20,
},
text: {
flex: 1,
bottom: 100,
left: 20,
position: 'absolute',
gap: 16,
},
title: {
fontSize: 32,
lineHeight: 32,
fontWeight: 'bold',
color: 'white',
},
subtitle: {
fontSize: 16,
lineHeight: 16,
fontWeight: '500',
color: 'white',
},
})