2017-08-22 01:24:41 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2017-08-21 00:11:46 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { Animated, Text } from 'react-native';
|
|
|
|
|
|
|
|
export default class Fade extends React.Component {
|
2017-08-22 01:24:41 +00:00
|
|
|
static propTypes = {
|
|
|
|
visible: PropTypes.bool.isRequired,
|
2017-08-22 01:43:29 +00:00
|
|
|
style: Animated.View.propTypes.style,
|
|
|
|
children: PropTypes.oneOfType([
|
|
|
|
PropTypes.arrayOf(PropTypes.node),
|
|
|
|
PropTypes.node
|
|
|
|
])
|
2017-08-22 01:24:41 +00:00
|
|
|
}
|
|
|
|
|
2017-08-21 00:11:46 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2018-09-25 19:28:42 +00:00
|
|
|
const { visible } = this.props;
|
2017-08-21 00:11:46 +00:00
|
|
|
this.state = {
|
2018-09-25 19:28:42 +00:00
|
|
|
visible
|
2017-08-21 00:11:46 +00:00
|
|
|
};
|
2018-09-25 19:28:42 +00:00
|
|
|
this._visibility = new Animated.Value(visible ? 1 : 0);
|
2017-08-21 00:11:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if (nextProps.visible) {
|
|
|
|
this.setState({ visible: true });
|
|
|
|
}
|
|
|
|
Animated.timing(this._visibility, {
|
|
|
|
toValue: nextProps.visible ? 1 : 0,
|
2018-02-08 14:08:50 +00:00
|
|
|
duration: 300,
|
|
|
|
useNativeDriver: true
|
2017-08-21 00:11:46 +00:00
|
|
|
}).start(() => {
|
|
|
|
this.setState({ visible: nextProps.visible });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { visible } = this.state;
|
2017-08-22 01:24:41 +00:00
|
|
|
const { style, children, ...rest } = this.props;
|
2017-08-21 00:11:46 +00:00
|
|
|
|
|
|
|
const containerStyle = {
|
|
|
|
opacity: this._visibility.interpolate({
|
|
|
|
inputRange: [0, 1],
|
|
|
|
outputRange: [0, 1]
|
|
|
|
}),
|
|
|
|
transform: [
|
|
|
|
{
|
|
|
|
scale: this._visibility.interpolate({
|
|
|
|
inputRange: [0, 1],
|
|
|
|
outputRange: [1.1, 1]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
const combinedStyle = [containerStyle, style];
|
|
|
|
return (
|
2018-09-25 19:28:42 +00:00
|
|
|
<Animated.View style={visible ? combinedStyle : containerStyle} {...rest}>
|
|
|
|
<Text>{visible ? children : null}</Text>
|
2017-08-21 00:11:46 +00:00
|
|
|
</Animated.View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|