-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathApp.js
More file actions
166 lines (156 loc) · 3.84 KB
/
App.js
File metadata and controls
166 lines (156 loc) · 3.84 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import React, {useRef} from 'react';
import {
SafeAreaView,
StyleSheet,
Image,
View,
Text,
Animated,
} from 'react-native';
import faker from 'faker';
const HEADER_MAX_HEIGHT = 240;
const HEADER_MIN_HEIGHT = 84;
const HEADER_SCROLL_DISTANCE = HEADER_MAX_HEIGHT - HEADER_MIN_HEIGHT;
const DATA = Array(10)
.fill(null)
.map((_, idx) => ({
id: idx,
avatar: faker.image.avatar(),
fullName: `${faker.name.firstName()} ${faker.name.lastName()}`,
}));
function App() {
const scrollY = useRef(new Animated.Value(0)).current;
const headerTranslateY = scrollY.interpolate({
inputRange: [0, HEADER_SCROLL_DISTANCE],
outputRange: [0, -HEADER_SCROLL_DISTANCE],
extrapolate: 'clamp',
});
const imageOpacity = scrollY.interpolate({
inputRange: [0, HEADER_SCROLL_DISTANCE / 2, HEADER_SCROLL_DISTANCE],
outputRange: [1, 1, 0],
extrapolate: 'clamp',
});
const imageTranslateY = scrollY.interpolate({
inputRange: [0, HEADER_SCROLL_DISTANCE],
outputRange: [0, 100],
extrapolate: 'clamp',
});
const titleScale = scrollY.interpolate({
inputRange: [0, HEADER_SCROLL_DISTANCE / 2, HEADER_SCROLL_DISTANCE],
outputRange: [1, 1, 0.9],
extrapolate: 'clamp',
});
const titleTranslateY = scrollY.interpolate({
inputRange: [0, HEADER_SCROLL_DISTANCE / 2, HEADER_SCROLL_DISTANCE],
outputRange: [0, 0, -8],
extrapolate: 'clamp',
});
const renderListItem = (item) => (
<View key={item.id} style={styles.card}>
<Image style={styles.avatar} source={{uri: item.avatar}} />
<Text style={styles.fullNameText}>{item.fullName}</Text>
</View>
);
return (
<SafeAreaView style={styles.saveArea}>
<Animated.ScrollView
contentContainerStyle={{paddingTop: HEADER_MAX_HEIGHT - 32}}
scrollEventThrottle={16}
onScroll={Animated.event(
[{nativeEvent: {contentOffset: {y: scrollY}}}],
{useNativeDriver: true},
)}>
{DATA.map(renderListItem)}
</Animated.ScrollView>
<Animated.View
style={[styles.header, {transform: [{translateY: headerTranslateY}]}]}>
<Animated.Image
style={[
styles.headerBackground,
{
opacity: imageOpacity,
transform: [{translateY: imageTranslateY}],
},
]}
source={require('./assets/management.jpg')}
/>
</Animated.View>
<Animated.View
style={[
styles.topBar,
{
transform: [{scale: titleScale}, {translateY: titleTranslateY}],
},
]}>
<Text style={styles.title}>Management</Text>
</Animated.View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
saveArea: {
flex: 1,
backgroundColor: '#eff3fb',
},
card: {
flexDirection: 'row',
alignItems: 'center',
shadowColor: '#402583',
backgroundColor: '#ffffff',
shadowOffset: {
width: 0,
height: 0,
},
shadowOpacity: 0.1,
shadowRadius: 6,
elevation: 1,
borderRadius: 10,
marginHorizontal: 12,
marginTop: 12,
paddingHorizontal: 16,
paddingVertical: 12,
},
header: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
backgroundColor: '#62d1bc',
overflow: 'hidden',
height: HEADER_MAX_HEIGHT,
},
headerBackground: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
width: null,
height: HEADER_MAX_HEIGHT,
resizeMode: 'cover',
},
topBar: {
marginTop: 40,
height: 50,
alignItems: 'center',
justifyContent: 'center',
position: 'absolute',
top: 0,
left: 0,
right: 0,
},
title: {
color: 'white',
fontSize: 20,
},
avatar: {
height: 54,
width: 54,
resizeMode: 'contain',
borderRadius: 54 / 2,
},
fullNameText: {
fontSize: 16,
marginLeft: 24,
},
});
export default App;