Skip to content

Instantly share code, notes, and snippets.

@pachun
Created May 24, 2019 01:27
Show Gist options
  • Select an option

  • Save pachun/b3f2b2e3aa2a13c0d5621dfbd83397d3 to your computer and use it in GitHub Desktop.

Select an option

Save pachun/b3f2b2e3aa2a13c0d5621dfbd83397d3 to your computer and use it in GitHub Desktop.
import * as 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",
},
})
interface IProps {
thumbnailSource: string
source: string
style: object
}
class ProgressiveImage extends React.Component<IProps> {
private thumbnailAnimated = new Animated.Value(0)
private imageAnimated = new Animated.Value(0)
public 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>
)
}
private handleThumbnailLoad = () => {
Animated.timing(this.thumbnailAnimated, {
toValue: 1,
}).start()
}
private onImageLoad = () => {
Animated.timing(this.imageAnimated, {
toValue: 1,
}).start()
}
}
export default ProgressiveImage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment