Created
January 28, 2017 18:19
-
-
Save mmazzarolo/1b538d10813f249626e4876b3ed91ca4 to your computer and use it in GitHub Desktop.
Super simple circle animation overlay for React-Native
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
/* @flow */ | |
import React, { Component } from 'react' | |
import { View } from 'react-native-animatable' | |
import metrics from 'src/config/metrics' | |
type Props = { | |
isVisible: boolean, | |
backgroundColor: string, | |
animationTiming?: boolean | |
} | |
export default class CircleAnimation extends Component<void, Props, void> { | |
_viewRef: any = null | |
componentDidUpdate (prevProps: Props) { | |
const previouslyVisible = prevProps.isVisible | |
const currentlyVisible = this.props.isVisible | |
if (!previouslyVisible && currentlyVisible) { | |
this._viewRef.animate('zoomIn', this.props.animationTiming) | |
} else if (previouslyVisible && !currentlyVisible) { | |
this._viewRef.animate('zoomOut', this.props.animationTiming) | |
} | |
} | |
render () { | |
const size = metrics.DEVICE_HEIGHT * 1.3 | |
const style = { | |
position: 'absolute', | |
bottom: (metrics.DEVICE_HEIGHT / 2) - (size / 2), | |
left: (metrics.DEVICE_WIDTH / 2) - (size / 2), | |
height: size, | |
width: size, | |
backgroundColor: this.props.backgroundColor, | |
borderRadius: size / 2 | |
} | |
return ( | |
<View | |
ref={(ref) => { this._viewRef = ref }} | |
style={style} | |
pointerEvents={'box-none'} | |
/> | |
) | |
} | |
} |
Author
mmazzarolo
commented
Jan 28, 2017
awesome 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment