Skip to content

Instantly share code, notes, and snippets.

@AakashRaina
Created December 4, 2018 12:05
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 AakashRaina/fc33d0d4f0ad7c7f670d609a42066b33 to your computer and use it in GitHub Desktop.
Save AakashRaina/fc33d0d4f0ad7c7f670d609a42066b33 to your computer and use it in GitHub Desktop.
class ProgressiveImage extends React.Component {
constructor(props) {
super(props);
this.placeholderAnimated = new Animated.Value(0);
this.imageAnimated = new Animated.Value(0);
}
handlePlaceholderLoad = () => {
Animated.timing(this.placeholderAnimated, {
toValue: 1
}).start();
};
onImageLoad = () => {
Animated.timing(this.imageAnimated, {
toValue: 1
}).start();
};
render() {
const { source, style } = this.props;
return (
<View style={{ backgroundColor: "#e1e4e8" }}>
<Animated.Image
source={require("/assests/Images/img-placeholder.jpg")}
style={style}
blurRadius={2.5}
onLoad={this.handlePlaceholderLoad}
/>
<Animated.Image
source={source}
style={[
style,
{ position: "absolute", top: 0, bottom: 0, right: 0, left: 0 }
]}
onLoad={this.onImageLoad}
/>
</View>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment