Created
April 16, 2018 17:03
-
-
Save suhanlee/1b197d825e9717f4d1eb96e5075ca791 to your computer and use it in GitHub Desktop.
react-native-ui-animations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import PropTypes from 'prop-types'; | |
import { Animated, Easing } from 'react-native' | |
class SlideIn extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
height: new Animated.Value(0), | |
}; | |
} | |
updateSlideIn = () => { | |
if (this.props.slideIn) { | |
this.slideIn(); | |
} else { | |
this.slideOut(); | |
} | |
} | |
slideIn = () => { | |
Animated.timing( | |
this.state.height, | |
{ | |
toValue: this.props.height, | |
duration: 400, | |
easing: Easing.linear, | |
} | |
).start() | |
}; | |
slideOut = () => { | |
Animated.timing( | |
this.state.height, | |
{ | |
toValue: 0, | |
duration: 400, | |
easing: Easing.linear, | |
} | |
).start() | |
}; | |
componentWillReceiveProps(nextProps) { | |
if (this.props.slideIn !== nextProps.slideIn) { | |
this.updateSlideIn(); | |
} | |
} | |
render() { | |
const { | |
children, | |
style, | |
} = this.props; | |
return ( | |
<Animated.View | |
style={[{ | |
opacity: 1, | |
height: this.state.height, | |
backgroundColor: 'transparent', | |
}, style]} | |
> | |
{children} | |
</Animated.View> | |
); | |
} | |
} | |
SlideIn.propTypes = { | |
style: PropTypes.shape({}), | |
}; | |
export default SlideIn; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment