-
Notifications
You must be signed in to change notification settings - Fork 8
/
SlidingPane.js
54 lines (49 loc) · 1.2 KB
/
SlidingPane.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
import React, { Component } from 'react';
import { Animated, Dimensions } from 'react-native';
export default class SlidingPane extends React.Component {
constructor(props) {
super(props);
this.state = {
leftAnim: new Animated.Value(0)
};
}
warpLeft() {
var {width} = Dimensions.get('window');
this.setState({leftAnim: new Animated.Value(-width)});
}
slideLeft() {
var {width} = Dimensions.get('window');
Animated.spring(
this.state.leftAnim,
{toValue: -width}
).start();
}
warpCenter() {
this.setState({leftAnim: new Animated.Value(0)});
}
slideCenter() {
Animated.spring(
this.state.leftAnim,
{toValue: 0}
).start();
}
slideRight() {
var {width} = Dimensions.get('window');
Animated.spring(
this.state.leftAnim,
{toValue: width}
).start();
}
warpRight() {
var {width} = Dimensions.get('window');
this.setState({leftAnim: new Animated.Value(width)});
}
render() {
return (
<Animated.View
style={{ ...this.props.style, position: 'absolute', width: '100%', height: '100%', left: this.state.leftAnim }}>
{this.props.children}
</Animated.View>
);
}
}