This repository has been archived on 2022-12-12. You can view files and clone it, but cannot push or open issues or pull requests.
GiftGenie/components/ProgressiveImage.js

20 lines
760 B
JavaScript

import React, { Component } from 'react';
import { Image } from 'react-native';
export default class ProgressiveImage extends Component {
state = { showDefault: true, error: false };
render() {
var image = this.state.showDefault ? { uri: this.props.loadingUri } : ( this.state.error ? { uri: this.props.errorUri } : { uri: this.props.uri } );
if (image.uri == null) {
image = { uri: this.props.errorUri };
}
return (
<Image style={this.props.style}
source={image}
onLoadEnd={() => this.setState({showDefault: false})}
onError={() => this.setState({error: true})}
resizeMode={this.props.resizeMode}/>
);
}
}