Skip to content

Commit

Permalink
Merge pull request #7723 from mdneyazahmad/feat/7584-image-placeholder
Browse files Browse the repository at this point in the history
feat: add image loading placeholder
  • Loading branch information
mountiny authored Feb 23, 2022
2 parents 853db57 + 73c5eaa commit cc90f56
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions src/components/ImageWithSizeCalculation.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, {PureComponent} from 'react';
import {Image} from 'react-native';
import {Image, ActivityIndicator} from 'react-native';
import PropTypes from 'prop-types';
import Log from '../libs/Log';
import styles from '../styles/styles';
import makeCancellablePromise from '../libs/MakeCancellablePromise';
import themeColors from '../styles/themes/default';

const propTypes = {
/** Url for image to display */
Expand All @@ -29,6 +30,14 @@ const defaultProps = {
* it can be appropriately resized.
*/
class ImageWithSizeCalculation extends PureComponent {
constructor(props) {
super(props);

this.state = {
isLoading: true,
};
}

componentDidMount() {
this.calculateImageSize();
}
Expand Down Expand Up @@ -85,15 +94,26 @@ class ImageWithSizeCalculation extends PureComponent {

render() {
return (
<Image
style={[
styles.w100,
styles.h100,
this.props.style,
]}
source={{uri: this.props.url}}
resizeMode="contain"
/>
<>
<Image
style={[
styles.w100,
styles.h100,
this.state.isLoading && styles.dNone,
this.props.style,
]}
source={{uri: this.props.url}}
resizeMode="contain"
onLoadEnd={() => this.setState({isLoading: false})}
/>
{this.state.isLoading && (
<ActivityIndicator
size="large"
style={[styles.flex1]}
color={themeColors.textSupporting}
/>
)}
</>
);
}
}
Expand Down

0 comments on commit cc90f56

Please sign in to comment.