-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathdisplay.js
91 lines (69 loc) · 2.05 KB
/
display.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import React, { Component } from 'react';
import {
View,
Text,
StyleSheet,
Dimensions,
} from 'react-native';
import * as Animatable from 'react-native-animatable';
const screen = Dimensions.get('window');
const WIDTH = screen.width;
const HEIGHT = screen.height;
const DEFAULT_DURATION = 250;
export default class Display extends Component {
constructor(props) {
super(props);
this.state = { enable: this.props.enable };
}
onEndAnimation(endState) {
if (endState.finished == true)
this.setState({enable: false});
}
shouldComponentUpdate(nextProps) {
return true;
}
componentWillUpdate(nextProps, nextState) {
if (nextProps.enable != this.props.enable) {
if (nextProps.enable == false) {
let duration = nextProps.exitDuration || nextProps.defaultDuration || DEFAULT_DURATION;
if (nextProps.exit != null) {
this.refs.display[nextProps.exit](duration).then((endState) => this.onEndAnimation(endState));
}
else
nextState.enable = false;
}
else
nextState.enable = true;
}
}
enableStyle() {
if (this.state.enable)
return {};
return {
position: 'absolute',
top: HEIGHT,
left: WIDTH,
height: 0,
width: 0,
};
}
render() {
if (this.state.enable == false && this.props.keepAlive != true)
return null;
return (
<Animatable.View ref="display" style={[this.props.style, this.enableStyle.bind(this)()]}>
{this.props.children}
</Animatable.View>
);
}
componentDidUpdate(prevProps, prevState) {
if (prevProps.enable != this.props.enable)
if (this.props.enable == true) {
this.refs.display.stopAnimation();
let duration = this.props.enterDuration || this.props.defaultDuration || DEFAULT_DURATION;
if (this.props.enter != null) {
this.refs.display[this.props.enter](duration).then((endState) => { });
}
}
}
}