forked from shoutem/animation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFadeIn.js
More file actions
63 lines (61 loc) · 1.55 KB
/
Copy pathFadeIn.js
File metadata and controls
63 lines (61 loc) · 1.55 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
import React, { Component } from 'react';
import { Animated, View } from 'react-native';
import { DriverShape } from './DriverShape';
/*
* FadeIn Component adds fade in effect to its children components.
* Connect it to an animation driver and pass the input range to animate it.
* e.g.:
* ...
* const driver = new ScrollDriver();
*
* return (
* <ScrollView
* {...driver.scrollViewProps}
* >
* <FadeIn
* driver={driver}
* inputRange={[100,150]}
* >
* <Image />
* </FadeIn>
* </ScrollView>
* );
*
* ...
* Above code will create scroll dependent fade in animation over Image component
* from scroll position 100, to scroll position 150 where image is fully transparent at
* scroll position 100, and opaque at scroll position 150
*/
export class FadeIn extends Component {
static propTypes = {
/**
* An instance of animation driver, usually ScrollDriver
*/
driver: DriverShape.isRequired,
/**
* Components to which an effect will be applied
*/
children: React.PropTypes.node,
/**
* pair of [start, end] values from animation driver, how
* children would fade in
*/
inputRange: React.PropTypes.array,
}
render() {
const { driver, children, inputRange = [0, 1], style } = this.props;
return (
<Animated.View
style={[style, {
opacity: driver.value.interpolate({
inputRange,
outputRange: [0, 1],
extrapolate: 'clamp',
}),
}]}
>
{children}
</Animated.View>
);
}
}