forked from shoutem/animation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeroHeader.js
More file actions
74 lines (72 loc) · 1.83 KB
/
Copy pathHeroHeader.js
File metadata and controls
74 lines (72 loc) · 1.83 KB
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
import React, { Component } from 'react';
import { View } from 'react-native';
import { ZoomOut } from './ZoomOut';
import { Parallax } from './Parallax';
import { DriverShape } from './DriverShape';
/*
* HeroHeader adds complex effect to its children components.
* Connect it to driver to animate it.
* e.g.:
* ...
* const driver = new ScrollDriver();
*
* return (
* <Screen styleName="full-screen">
* <HeroHeader driver={driver}>
* <Image />
* </HeroHeader>
* <ScrollView
* {...driver.scrollViewProps}
* >
* <Title>Title</Title>
* </ScrollView>
* </Screen>
* );
*
* ...
* Above code will create scroll dependent parallax animation over Image component
* where image will be scrolled 1.5 times faster than Title and the image will have
* a zoom in effect when the scroll reaches the top of the screen (on bounce)
*/
export class HeroHeader extends Component {
static propTypes = {
driver: DriverShape.isRequired,
/**
* Components to which an effect will be applied
*/
children: React.PropTypes.node,
}
constructor(props) {
super(props);
this.onLayout = this.onLayout.bind(this);
this.state = {
height: 240,
};
}
onLayout(event) {
const { height } = event.nativeEvent.layout;
this.setState({ height });
}
render() {
const { driver, children } = this.props;
return (
<View onLayout={this.onLayout}>
<ZoomOut
driver={driver}
inputRange={[-(0.9 * this.state.height), 0]}
maxFactor={3}
>
<Parallax
driver={driver}
scrollSpeed={0.5}
insideScroll
header
extrapolation={{ extrapolateLeft: 'clamp' }}
>
{children}
</Parallax>
</ZoomOut>
</View>
);
}
}