-
Notifications
You must be signed in to change notification settings - Fork 6
/
App.js
100 lines (91 loc) · 2.56 KB
/
App.js
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
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
Animated,
Dimensions,
Platform,
ScrollView,
StyleSheet,
Text,
View
} from 'react-native';
import str from './content';
const HEADER_EXPANDED_HEIGHT = 300;
const HEADER_COLLAPSED_HEIGHT = 60;
const { width: SCREEN_WIDTH } = Dimensions.get("screen")
export default class App extends Component {
constructor() {
super();
this.state = {
scrollY: new Animated.Value(0)
}
}
render() {
const headerHeight = this.state.scrollY.interpolate({
inputRange: [0, HEADER_EXPANDED_HEIGHT-HEADER_COLLAPSED_HEIGHT],
outputRange: [HEADER_EXPANDED_HEIGHT, HEADER_COLLAPSED_HEIGHT],
extrapolate: 'clamp'
});
const headerTitleOpacity = this.state.scrollY.interpolate({
inputRange: [0, HEADER_EXPANDED_HEIGHT-HEADER_COLLAPSED_HEIGHT],
outputRange: [0, 1],
extrapolate: 'clamp'
});
const heroTitleOpacity = this.state.scrollY.interpolate({
inputRange: [0, HEADER_EXPANDED_HEIGHT-HEADER_COLLAPSED_HEIGHT],
outputRange: [1, 0],
extrapolate: 'clamp'
});
const headerTitle = 'HEADER'
return (
<View style={styles.container}>
<Animated.View style={[styles.header, { height: headerHeight }]}>
<Animated.Text style={{textAlign: 'center', fontSize: 18, color: 'black', marginTop: 28, opacity: headerTitleOpacity}}>{headerTitle}</Animated.Text>
<Animated.Text style={{textAlign: 'center', fontSize: 32, color: 'black', position: 'absolute', bottom: 16, left: 16, opacity: heroTitleOpacity}}>{headerTitle}</Animated.Text>
</Animated.View>
<ScrollView
contentContainerStyle={styles.scrollContainer}
onScroll={Animated.event(
[{ nativeEvent: {
contentOffset: {
y: this.state.scrollY
}
}
}])
}
scrollEventThrottle={16}>
<Text style={styles.title}>This is Title</Text>
<Text style={styles.content}>{str}</Text>
</ScrollView>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#eaeaea',
},
scrollContainer: {
padding: 16,
paddingTop: HEADER_EXPANDED_HEIGHT
},
header: {
backgroundColor: 'lightblue',
position: 'absolute',
width: SCREEN_WIDTH,
top: 0,
left: 0,
zIndex: 9999
},
title: {
marginVertical: 16,
color: "black",
fontWeight: "bold",
fontSize: 24
}
});