Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Commit a6ebd36

Browse files
committed
handle uri prop changes - if we receive a different uri we need to unload the current file and load the new one
1 parent 6722d08 commit a6ebd36

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

lib/imageCacheHoc.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,30 @@ export default function imageCacheHoc(Image, options = {}) {
167167

168168
}
169169

170+
async componentWillReceiveProps(nextProps) {
171+
const uri = traverse(this.props).get(['source', 'uri']);
172+
const nextUri = traverse(nextProps).get(['source', 'uri']);
173+
if (uri === nextUri) return;
174+
175+
const fileName = await this.fileSystem.getFileNameFromUrl(uri);
176+
const nextFileName = await this.fileSystem.getFileNameFromUrl(nextUri);
177+
178+
FileSystem.unlockCacheFile(fileName, this.componentId);
179+
FileSystem.lockCacheFile(nextFileName, this.componentId);
180+
181+
const { permanent } = this.props;
182+
let localFilePath = null;
183+
try {
184+
localFilePath = await this.fileSystem.getLocalFilePathFromUrl(nextUri, !!permanent);
185+
} catch (error) {
186+
console.warn(error); // eslint-disable-line no-console
187+
}
188+
189+
if (this._isMounted && localFilePath) {
190+
this.setState({ localFilePath });
191+
}
192+
}
193+
170194
async componentWillUnmount() {
171195

172196
// Track component mount status to avoid calling setState() on unmounted component.
@@ -207,4 +231,4 @@ export default function imageCacheHoc(Image, options = {}) {
207231

208232
};
209233

210-
}
234+
}

0 commit comments

Comments
 (0)