Skip to content

Commit 89f07eb

Browse files
committed
fix(android): immediately load a version from cache + prevent over fetching
1 parent 3fb29c8 commit 89f07eb

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,20 @@ private void load(final FastImageViewWithUrl view, @NonNull final ReadableMap so
162162
private void loadImage(final FastImageViewWithUrl view, final String url, @Nullable final RequestOptions options, final @Nullable String key) {
163163
String prevEtag = ObjectBox.getEtagByUrl(url);
164164

165+
// when we have a prevEtag there will be (very likely) a cached version
166+
// of the image that we want to display even before sending out any req
167+
if (prevEtag != null && requestManager != null) {
168+
RequestBuilder<Drawable> builder = requestManager
169+
.load(url)
170+
.onlyRetrieveFromCache(true)
171+
.signature(new ObjectKey(prevEtag))
172+
.listener(new FastImageRequestListener(key));
173+
if (options != null) {
174+
builder = builder.apply(options);
175+
}
176+
builder.into(view);
177+
}
178+
165179
// We need to make a head request to the URL with the ETAG attached.
166180
// - When we get a new etag Glide will send out another request (as signature has changed)
167181
// - If the signature (etag) didn't change, Glide won't bother sending out a request
@@ -216,7 +230,8 @@ private void loadImageWithSignature(
216230
if (prevSignature != null) {
217231
// Create a "thumbnail" which is literally the cached image while we load the new image
218232
RequestBuilder<Drawable> thumbnailRequest = requestManager
219-
.load(url);
233+
.load(url)
234+
.onlyRetrieveFromCache(true);
220235
thumbnailRequest = thumbnailRequest.signature(new ObjectKey(prevSignature));
221236
imageRequest = imageRequest
222237
.thumbnail(thumbnailRequest);

0 commit comments

Comments
 (0)