forked from maphongba008/react-native-animated-header
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimatedHeader.js
More file actions
39 lines (36 loc) · 1006 Bytes
/
AnimatedHeader.js
File metadata and controls
39 lines (36 loc) · 1006 Bytes
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
import React, { Component } from 'react';
import {
View,
} from 'react-native';
import Header from './Header';
export default class AnimatedHeader extends React.PureComponent {
_onScroll = (e) => {
this.header.onScroll(e);
}
render() {
const arr = React.Children.toArray(this.props.children);
if (arr.length === 0) {
console.error('AnimatedHeader must have ScrollView or FlatList as a child');
}
if (arr.length > 1) {
console.error('Invalid child, only 1 child accepted')
}
const { headerMaxHeight } = this.props;
const child = React.cloneElement(arr[0], {
style: {flex: 1},
ref: (r) => this.scrollView = r,
scrollEventThrottle: 16,
onScroll: this._onScroll,
contentContainerStyle: { paddingTop: headerMaxHeight || 200 }
});
return (
<View style={this.props.style}>
{child}
<Header
{...this.props}
ref={(r) => {this.header = r;}}
/>
</View>
);
}
}