Skip to content

Instantly share code, notes, and snippets.

@diego3g
Created February 6, 2018 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diego3g/d0e071b4dbd00c0a311c45ebc3865840 to your computer and use it in GitHub Desktop.
Save diego3g/d0e071b4dbd00c0a311c45ebc3865840 to your computer and use it in GitHub Desktop.
/* Core */
import React, { Component } from 'react';
/* Presentational */
import { View, Image, Animated } from 'react-native';
export default class PlaceholderImage extends Component {
state = {
opacity: new Animated.Value(0),
}
onLoad = event => {
Animated.timing(this.state.opacity, {
toValue: 1,
duration: 300,
}).start();
}
render() {
return (
<View
style={{
backgroundColor: '#EEE',
width: this.props.style.width || '100%',
height: this.props.style.height || '100%',
}}
>
<Image
{...this.props}
source={require('./placeholder.png')}
/>
<Animated.Image
{...this.props}
style={[
this.props.style,
{ position: 'absolute', opacity: this.state.opacity }
]}
onLoad={this.onLoad}
/>
</View>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment