Skip to content

For anyone use SDWebImage or react-native-fast-image #135

Closed
@zhigang1992

Description

@zhigang1992

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @merryjs/[email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/@merryjs/photo-viewer/MerryPhotoViewer.podspec b/node_modules/@merryjs/photo-viewer/MerryPhotoViewer.podspec
index 9e88af7..27413c5 100644
--- a/node_modules/@merryjs/photo-viewer/MerryPhotoViewer.podspec
+++ b/node_modules/@merryjs/photo-viewer/MerryPhotoViewer.podspec
@@ -16,4 +16,5 @@ Pod::Spec.new do |s|
 
   s.dependency "React"
   s.dependency "NYTPhotoViewer", '2.0.0'
+  s.dependency 'SDWebImage'
 end
diff --git a/node_modules/@merryjs/photo-viewer/ios/MerryPhotoView.m b/node_modules/@merryjs/photo-viewer/ios/MerryPhotoView.m
index af8ea83..a3266f6 100644
--- a/node_modules/@merryjs/photo-viewer/ios/MerryPhotoView.m
+++ b/node_modules/@merryjs/photo-viewer/ios/MerryPhotoView.m
@@ -2,6 +2,7 @@
 #import "MerryPhotoView.h"
 #import <React/RCTImageLoader.h>
 #import <Foundation/Foundation.h>
+#import <SDWebImage/SDWebImage.h>
 
 @implementation MerryPhotoView {
 
@@ -159,26 +160,16 @@ - (void)updatePhotoAtIndex:(NYTPhotosViewController*)photosViewController
     MerryPhoto* currentPhoto = [self.dataSource.photos objectAtIndex:current];
     MerryPhotoData* d = self.reactPhotos[current];
 
-    [[_bridge moduleForClass:[RCTImageLoader class]] loadImageWithURLRequest:d.source.request
-        size:d.source.size
-        scale:d.source.scale
-        clipped:YES
-        resizeMode:RCTResizeModeStretch
-        progressBlock:^(int64_t progress, int64_t total) {
-            //            NSLog(@"%lld %lld", progress, total);
+    [[SDWebImageManager sharedManager] loadImageWithURL:d.source.request.URL options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
+        // ignore
+    } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
+        if (image) {
+            dispatch_async(dispatch_get_main_queue(), ^{
+                currentPhoto.image = image;
+                [photosViewController updatePhoto:currentPhoto];
+            });
         }
-        partialLoadBlock:nil
-        completionBlock:^(NSError* error, UIImage* image) {
-            if (image) {
-                dispatch_async(dispatch_get_main_queue(), ^{
-
-                    currentPhoto.image = image;
-
-                    [photosViewController updatePhoto:currentPhoto];
-
-                });
-            }
-        }];
+    }];
 }
 
 #pragma mark - NYTPhotosViewControllerDelegate

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions