Skip to content

Commit

Permalink
Make ImageLoaderModule TurboModule-compatible
Browse files Browse the repository at this point in the history
Summary:
Modifying ImageLoaderModule to be TM-compatible by extending the generated abstract class and fixing the conflicting method signatures (int -> double).

Changelog: [Android] [Changed] Changing method signatures for ImageLoaderModule to accept double for requestId

Reviewed By: mdvacca

Differential Revision: D18435628

fbshipit-source-id: bc2a82bda49e339d1feebfe917b0862a1af15a1f
  • Loading branch information
Emily Janzer authored and facebook-github-bot committed Nov 18, 2019
1 parent 8797a5c commit 641e965
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ rn_android_library(
react_native_target("java/com/facebook/react/module/annotations:annotations"),
react_native_target("java/com/facebook/react/views/imagehelper:imagehelper"),
],
exported_deps = [
react_native_target("java/com/facebook/fbreact/specs:FBReactNativeSpec"),
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.facebook.datasource.DataSource;
import com.facebook.datasource.DataSubscriber;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.fbreact.specs.NativeImageLoaderAndroidSpec;
import com.facebook.imagepipeline.core.ImagePipeline;
import com.facebook.imagepipeline.image.CloseableImage;
import com.facebook.imagepipeline.request.ImageRequest;
Expand All @@ -25,7 +26,6 @@
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
Expand All @@ -35,7 +35,7 @@
import com.facebook.react.views.imagehelper.ImageSource;

@ReactModule(name = ImageLoaderModule.NAME)
public class ImageLoaderModule extends ReactContextBaseJavaModule
public class ImageLoaderModule extends NativeImageLoaderAndroidSpec
implements LifecycleEventListener {

private static final String ERROR_INVALID_URI = "E_INVALID_URI";
Expand Down Expand Up @@ -183,12 +183,15 @@ protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> data
* Prefetches the given image to the Fresco image disk cache.
*
* @param uriString the URI of the remote image to prefetch
* @param requestId the client-supplied request ID used to identify this request
* @param requestIdAsDouble the client-supplied request ID used to identify this request
* @param promise the promise that is fulfilled when the image is successfully prefetched or
* rejected when there is an error
*/
@ReactMethod
public void prefetchImage(final String uriString, final int requestId, final Promise promise) {
@Override
public void prefetchImage(
final String uriString, final double requestIdAsDouble, final Promise promise) {
final int requestId = (int) requestIdAsDouble;

if (uriString == null || uriString.isEmpty()) {
promise.reject(ERROR_INVALID_URI, "Cannot prefetch an image for an empty URI");
return;
Expand Down Expand Up @@ -228,9 +231,9 @@ protected void onFailureImpl(DataSource<Void> dataSource) {
prefetchSource.subscribe(prefetchSubscriber, CallerThreadExecutor.getInstance());
}

@ReactMethod
public void abortRequest(final int requestId) {
DataSource<Void> request = removeRequest(requestId);
@Override
public void abortRequest(double requestId) {
DataSource<Void> request = removeRequest((int) requestId);
if (request != null) {
request.close();
}
Expand Down

0 comments on commit 641e965

Please sign in to comment.