Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# react-native-image-cache-wrapper
# react-native-image-cache-wrapper - Strange error fixed version - Алдаа зассан хувилбар
[![npm](https://img.shields.io/npm/v/react-native-image-cache-wrapper.svg?style=flat-square)](https://www.npmjs.com/package/react-native-image-cache-wrapper)

The best react native image cache wrapper.
Expand Down
19 changes: 17 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ export default class CachedImage extends Component {
static defaultProps = {
expiration: 86400 * 7, // default cache a week
activityIndicator: null, // default not show an activity indicator
defaultSource: require('static/images/default.png')

};

static cacheDir = RNFetchBlob.fs.dirs.CacheDir + "/CachedImage/";

static sameURL = []
/**
* delete a cache file
* @param url
Expand Down Expand Up @@ -106,6 +109,12 @@ export default class CachedImage extends Component {
}

const cacheFile = _getCacheFilename(url);
if(CachedImage.sameURL.includes(cacheFile)){

success && success(cacheFile);
return
}
CachedImage.sameURL.push(cacheFile)

RNFetchBlob.fs.stat(cacheFile)
.then((stats) => {
Expand All @@ -118,6 +127,8 @@ export default class CachedImage extends Component {
})
.catch((error) => {
// not exist
// success && success(cacheFile)

_saveCacheFile(url, success, failure);
});
};
Expand Down Expand Up @@ -160,7 +171,7 @@ export default class CachedImage extends Component {
// cache failed use original source
if (this._mounted) {
setTimeout(() => {
this.setState({source: this.props.source});
this.setState({source: { uri: this.props.source}});
}, 0);
}
this._downloading = false;
Expand Down Expand Up @@ -190,6 +201,10 @@ export default class CachedImage extends Component {
if (!this._useDefaultSource && this.props.defaultSource) {
this._useDefaultSource = true;
setTimeout(() => {
if(this.props.source && this.props.source.uri ){
this.setState({source: this.props.source});
}
else
this.setState({source: this.props.defaultSource});
}, 0);
}
Expand Down Expand Up @@ -313,4 +328,4 @@ async function _saveCacheFile(url: string, success: Function, failure: Function)
} catch (error) {
failure && failure(error);
}
}
}