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
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,16 @@
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.request.Request;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.events.RCTEventEmitter;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -139,34 +134,9 @@ public void onAfterUpdate(
RCTEventEmitter eventEmitter = context.getJSModule(RCTEventEmitter.class);
int viewId = this.getId();

// Request the URL from cache to see if it exists there and if so pass the cache
// path as an argument in the onLoadStart event
requestManager
.asFile()
.load(glideUrl)
.onlyRetrieveFromCache(true)
.listener(new RequestListener<File>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<File> target, boolean isFirstResource) {
WritableNativeMap result = new WritableNativeMap();
result.putNull("cachePath");
eventEmitter.receiveEvent(viewId,
FastImageViewManager.REACT_ON_LOAD_START_EVENT,
result);
return false;
}

@Override
public boolean onResourceReady(File resource, Object model, Target<File> target, DataSource dataSource, boolean isFirstResource) {
WritableNativeMap result = new WritableNativeMap();
result.putString("cachePath", resource.getAbsolutePath());
eventEmitter.receiveEvent(viewId,
FastImageViewManager.REACT_ON_LOAD_START_EVENT,
result);
return false;
}
})
.submit();
eventEmitter.receiveEvent(viewId,
FastImageViewManager.REACT_ON_LOAD_START_EVENT,
new WritableNativeMap());
}

if (requestManager != null) {
Expand Down
14 changes: 2 additions & 12 deletions ios/FastImage/FFFastImageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ - (void) setOnFastImageError: (RCTDirectEventBlock)onFastImageError {
- (void) setOnFastImageLoadStart: (RCTDirectEventBlock)onFastImageLoadStart {
if (_source && !self.hasSentOnLoadStart) {
_onFastImageLoadStart = onFastImageLoadStart;
onFastImageLoadStart(@{});
self.hasSentOnLoadStart = YES;
} else {
_onFastImageLoadStart = onFastImageLoadStart;
Expand Down Expand Up @@ -187,18 +188,7 @@ - (void) reloadImage {
}

if (self.onFastImageLoadStart) {
NSString* cachePath = [[SDImageCache sharedImageCache] cachePathForKey:url];
BOOL isCached = [[SDImageCache sharedImageCache] diskImageDataExistsWithKey:url];
if (isCached) {
self.onFastImageLoadStart(@{
@"cachePath": cachePath
});
}
else {
self.onFastImageLoadStart(@{
@"cachePath": [NSNull null]
});
}
self.onFastImageLoadStart(@{});
self.hasSentOnLoadStart = YES;
} else {
self.hasSentOnLoadStart = NO;
Expand Down