Skip to content

Instantly share code, notes, and snippets.

@williamtran29
Last active April 25, 2017 10:56
Show Gist options
  • Save williamtran29/98f07b0ec25292f8f4a138bd83ddd353 to your computer and use it in GitHub Desktop.
Save williamtran29/98f07b0ec25292f8f4a138bd83ddd353 to your computer and use it in GitHub Desktop.
Create FadeIn Animation for any React Native Component
/* @flow */
import React, { Component, PropTypes } from 'react'
import {
Animated
} from 'react-native'
export default class FadeIn extends Component {
static propTypes = {
children: PropTypes.node,
inputRange: React.PropTypes.array,
style: PropTypes.any
}
constructor(props) {
super(props)
this._animatedValue = new Animated.Value(0)
}
componentDidMount() {
Animated.timing( // Uses easing functions
this._animatedValue, // The value to drive
{
toValue: 1, // Target
duration: 2000 // Configuration
},
).start() // Don't forget start!
}
render() {
const { children, inputRange = [0, 1], style } = this.props
const opacity = this._animatedValue.interpolate({
inputRange,
outputRange: [0, 1],
extrapolate: 'clamp'
})
return (
<Animated.View style={{ opacity, ...style }}>
{children}
</Animated.View>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment