Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zhigang1992 opened this issue Nov 1, 2021 · 1 comment
Closed

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

zhigang1992 opened this issue Nov 1, 2021 · 1 comment

Comments

@zhigang1992
Copy link

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.

@BANG88
Copy link
Member

BANG88 commented Nov 4, 2021

@zhigang1992 Nice try. 👍

@BANG88 BANG88 pinned this issue Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants