forked from maphongba008/react-native-animated-header
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimatedHeader.js
56 lines (52 loc) · 1.33 KB
/
AnimatedHeader.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
import React, { Component } from 'react';
import {
View,
} from 'react-native';
import Header from './Header';
type Props = {
style?: any;
backText?: string;
title?: string;
renderLeft?: () => React.Component;
renderRight?: () => React.Component;
backStyle?: any;
backTextStyle?: any;
titleStyle?: any;
toolbarColor?: string;
headerMaxHeight?: number;
disabled?: boolean;
noBorder?: boolean;
parallax?: boolean;
imageSource?: any;
};
export default class AnimatedHeader extends React.PureComponent<Props> {
_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>
);
}
}