Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
set minLoading time to image load
Browse files Browse the repository at this point in the history
  • Loading branch information
soliury committed Jun 25, 2016
1 parent e9a6193 commit 33fe1fe
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/components/base/CustomImage.js
Expand Up @@ -43,18 +43,24 @@ export default class CustomImage extends Component {

_loadImg(uri, maxImageWidth) {
if (!uri) return;
const startTime = new Date().getTime();
Image.getSize(uri, (w, h)=> {
if (w >= maxImageWidth) {
h = (maxImageWidth / w) * h;
w = maxImageWidth;
}
this.setState({
size: {
width: w,
height: h
},
isLoaded: true
});
let leftTime = 500 - (new Date().getTime() - startTime);
if (leftTime > 0) {
setTimeout(()=> {
this.setState({
size: {
width: w,
height: h
},
isLoaded: true
});
}, leftTime);
}
}, ()=> {
this.setState({
error: true
Expand Down Expand Up @@ -110,7 +116,7 @@ const styles = StyleSheet.create({
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'rgba(0,0,0,0.09)',
backgroundColor: 'rgba(0,0,0,0.05)',
borderRadius: 5,
margin: 10
},
Expand Down

0 comments on commit 33fe1fe

Please sign in to comment.