/
SlideOut.js
74 lines (70 loc) · 1.68 KB
/
SlideOut.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
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import DriverShape from '../../drivers/DriverShape';
import Slide from './Slide';
/*
* SlideOut Component adds slide out effect to its children components.
* Connect it to driver and pass the input range to animate it.
* e.g.:
* ...
* const driver = new ScrollDriver();
*
* return (
* <ScrollView
* {...driver.scrollViewProps}
* >
* <SlideOut
* driver={driver}
* inputRange={[100,150]}
* to="top left"
* >
* <Image />
* </SlideOut>
* </ScrollView>
* );
*
* ...
* Above code will create scroll dependent slide out of an Image to
* the top left corner of the screen between scroll position of 100 and 150
*/
export default class SlideOut extends PureComponent {
static propTypes = {
/**
* An instance of animation driver, usually ScrollDriver
*/
driver: DriverShape.isRequired,
/**
* Components to which an effect will be applied
*/
children: PropTypes.node.isRequired,
/**
* pair of [start, end] values from animation driver, how
* children would slide out
*/
inputRange: PropTypes.array,
/**
* position to where wrapped components should slide out
*/
to: PropTypes.string,
style: PropTypes.object,
};
static defaultProps = {
inputRange: [0, 1],
to: 'top left',
style: {},
};
render() {
const { driver, children, inputRange, style, to } = this.props;
return (
<Slide
driver={driver}
animationName="slideOut"
inputRange={inputRange}
direction={to}
style={style}
>
{children}
</Slide>
);
}
}