-
Notifications
You must be signed in to change notification settings - Fork 4
/
ExScreen.js
75 lines (66 loc) · 1.58 KB
/
ExScreen.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
'use strict';
let React = require('react-native');
let {
Animated,
ScrollView,
StyleSheet,
View,
} = React;
let ExHeader = require('./ExHeader');
const STATUS_BAR_HEIGHT = 20;
class ExScreen extends React.Component {
constructor(props, context) {
super(props, context);
this.state = {
headerScale: new Animated.Value(1),
scrollDistance: new Animated.Value(0),
};
}
render() {
let {
title,
headerColor,
scrollEnabled,
...props,
} = this.props;
return (
<View {...props}>
<View
ref={component => { this._scrollView = component; }}
contentContainerStyle={styles.contentContainer}
scrollEnabled={scrollEnabled}
showsVerticalScrollIndicator={false}
scrollEventThrottle={16}
onScroll={this._handleScroll.bind(this)}>
<View style={{ height: ExHeader.HEIGHT + STATUS_BAR_HEIGHT }} />
{props.children}
</View>
<ExHeader
title={title}
scrollDistance={this.state.scrollDistance}
style={[styles.header, { backgroundColor: headerColor }]}
/>
</View>
);
}
_handleScroll(event) {
let {
contentInset: { top: topInset },
contentOffset: { y: scrollY },
} = event.nativeEvent;
let scrollDistance = scrollY + topInset;
this.state.scrollDistance.setValue(scrollDistance);
}
}
let styles = StyleSheet.create({
contentContainer: {
paddingTop: 0,
},
header: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
},
});
module.exports = ExScreen;