-
-
Save ronal2do/11e926a230b9a2bb36a9e195d7d1ca71 to your computer and use it in GitHub Desktop.
Super simple circle animation overlay for React-Native
This file contains hidden or 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'} | |
/> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment