Created
May 21, 2019 12:54
-
-
Save shakogegia/33c35d1b753d409a46405bbdeb40f8b0 to your computer and use it in GitHub Desktop.
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
import React from 'react'; | |
import { View, StyleSheet, Animated } from 'react-native'; | |
const styles = StyleSheet.create({ | |
imageOverlay: { | |
position: 'absolute', | |
left: 0, | |
right: 0, | |
bottom: 0, | |
top: 0, | |
}, | |
container: { | |
backgroundColor: '#e1e4e8', | |
}, | |
}); | |
class ProgressiveImage extends React.Component { | |
thumbnailAnimated = new Animated.Value(0); | |
imageAnimated = new Animated.Value(0); | |
handleThumbnailLoad = () => { | |
Animated.timing(this.thumbnailAnimated, { | |
toValue: 1, | |
}).start(); | |
} | |
onImageLoad = () => { | |
Animated.timing(this.imageAnimated, { | |
toValue: 1, | |
}).start(); | |
} | |
render() { | |
const { | |
thumbnailSource, | |
source, | |
style, | |
...props | |
} = this.props; | |
return ( | |
<View style={styles.container}> | |
<Animated.Image | |
{...props} | |
source={thumbnailSource} | |
style={[style, { opacity: this.thumbnailAnimated }]} | |
onLoad={this.handleThumbnailLoad} | |
blurRadius={1} | |
/> | |
<Animated.Image | |
{...props} | |
source={source} | |
style={[styles.imageOverlay, { opacity: this.imageAnimated }, style]} | |
onLoad={this.onImageLoad} | |
/> | |
</View> | |
); | |
} | |
} | |
export default ProgressiveImage; |
Author
shakogegia
commented
May 21, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment