-
Notifications
You must be signed in to change notification settings - Fork 4
/
ExHeader.js
86 lines (77 loc) · 1.79 KB
/
ExHeader.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
'use strict';
let React = require('react-native');
let {
Animated,
Easing,
StyleSheet,
View,
} = React;
let BODY_HEIGHT = 44;
let TITLE_MARGIN_TOP = 12;
let STATUS_BAR_HEIGHT = 20;
class ExHeader extends React.Component {
render() {
let {
title,
scrollDistance,
...props,
} = this.props;
let bodyStyle = {
opacity: scrollDistance.interpolate({
inputRange: [0, BODY_HEIGHT],
outputRange: [1, 0],
easing: Easing.in(Easing.linear),
extrapolate: 'clamp',
}),
height: scrollDistance.interpolate({
inputRange: [0, BODY_HEIGHT],
outputRange: [BODY_HEIGHT, 0],
extrapolate: 'clamp',
}),
};
let titleStyle = {
transform: [{
scale: scrollDistance.interpolate({
inputRange: [0, BODY_HEIGHT],
outputRange: [1, 0],
extrapolate: 'clamp',
}),
}],
marginTop: scrollDistance.interpolate({
inputRange: [0, BODY_HEIGHT],
outputRange: [TITLE_MARGIN_TOP, -STATUS_BAR_HEIGHT],
extrapolate: 'clamp',
}),
};
return (
<View {...props} style={[styles.container, props.style]}>
<View style={styles.statusBarStrut} />
<Animated.View style={[styles.body, bodyStyle]}>
<Animated.Text style={[styles.titleText, titleStyle]}>
{title}
</Animated.Text>
</Animated.View>
</View>
);
}
}
ExHeader.HEIGHT = BODY_HEIGHT;
let styles = StyleSheet.create({
container: {
overflow: 'hidden',
},
statusBarStrut: {
height: STATUS_BAR_HEIGHT,
},
body: {
height: BODY_HEIGHT,
},
titleText: {
color: '#fff',
fontSize: 17,
fontWeight: 'bold',
marginTop: TITLE_MARGIN_TOP,
alignSelf: 'center',
},
});
module.exports = ExHeader;