DylanVann / react-native-fast-image

🚩 FastImage, performant React Native image component.
MIT License
8.21k stars 1.51k forks source link

Patch for fix #1045

Open krunal54 opened 2 months ago

krunal54 commented 2 months ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-fast-image@8.6.3 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java b/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java
index d9dbd99..1c67401 100644
--- a/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java
+++ b/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java
@@ -11,7 +11,7 @@ import com.facebook.react.views.imagehelper.ImageSource;

 import javax.annotation.Nullable;

-public class FastImageSource extends ImageSource {
+public class FastImageSource {
     private static final String DATA_SCHEME = "data";
     private static final String LOCAL_RESOURCE_SCHEME = "res";
     private static final String ANDROID_RESOURCE_SCHEME = "android.resource";
@@ -19,6 +19,7 @@ public class FastImageSource extends ImageSource {
     private static final String LOCAL_FILE_SCHEME = "file";
     private final Headers mHeaders;
     private Uri mUri;
+    private final ImageSource imageSource; // Composition instead of inheritance

     public static boolean isBase64Uri(Uri uri) {
         return DATA_SCHEME.equals(uri.getScheme());
@@ -49,9 +50,9 @@ public class FastImageSource extends ImageSource {
     }

     public FastImageSource(Context context, String source, double width, double height, @Nullable Headers headers) {
-        super(context, source, width, height);
+        imageSource = new ImageSource(context, source, width, height); // Create ImageSource instance
         mHeaders = headers == null ? Headers.DEFAULT : headers;
-        mUri = super.getUri();
+        mUri = imageSource.getUri(); // Get URI from ImageSource

         if (isResource() && TextUtils.isEmpty(mUri.toString())) {
             throw new Resources.NotFoundException("Local Resource Not Found. Resource: '" + getSource() + "'.");
@@ -59,12 +60,11 @@ public class FastImageSource extends ImageSource {

         if (isLocalResourceUri(mUri)) {
             // Convert res:/ scheme to android.resource:// so
-            // glide can understand the uri.
+            // Glide can understand the URI.
             mUri = Uri.parse(mUri.toString().replace("res:/", ANDROID_RESOURCE_SCHEME + "://" + context.getPackageName() + "/"));
         }
     }

-
     public boolean isBase64Resource() {
         return mUri != null && FastImageSource.isBase64Uri(mUri);
     }
@@ -97,7 +97,6 @@ public class FastImageSource extends ImageSource {
         return getGlideUrl();
     }

-    @Override
     public Uri getUri() {
         return mUri;
     }
@@ -109,4 +108,8 @@ public class FastImageSource extends ImageSource {
     public GlideUrl getGlideUrl() {
         return new GlideUrl(getUri().toString(), getHeaders());
     }
+
+    public String getSource() {
+        return imageSource.getSource(); // Delegate to ImageSource
+    }
 }
\ No newline at end of file

This issue body was partially generated by patch-package.

kodeandoec commented 2 months ago

sorry for the question, how i can patch package? Can you get me instructions please?

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-fast-image@8.6.3 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java b/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java
index d9dbd99..1c67401 100644
--- a/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java
+++ b/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java
@@ -11,7 +11,7 @@ import com.facebook.react.views.imagehelper.ImageSource;

 import javax.annotation.Nullable;

-public class FastImageSource extends ImageSource {
+public class FastImageSource {
     private static final String DATA_SCHEME = "data";
     private static final String LOCAL_RESOURCE_SCHEME = "res";
     private static final String ANDROID_RESOURCE_SCHEME = "android.resource";
@@ -19,6 +19,7 @@ public class FastImageSource extends ImageSource {
     private static final String LOCAL_FILE_SCHEME = "file";
     private final Headers mHeaders;
     private Uri mUri;
+    private final ImageSource imageSource; // Composition instead of inheritance

     public static boolean isBase64Uri(Uri uri) {
         return DATA_SCHEME.equals(uri.getScheme());
@@ -49,9 +50,9 @@ public class FastImageSource extends ImageSource {
     }

     public FastImageSource(Context context, String source, double width, double height, @Nullable Headers headers) {
-        super(context, source, width, height);
+        imageSource = new ImageSource(context, source, width, height); // Create ImageSource instance
         mHeaders = headers == null ? Headers.DEFAULT : headers;
-        mUri = super.getUri();
+        mUri = imageSource.getUri(); // Get URI from ImageSource

         if (isResource() && TextUtils.isEmpty(mUri.toString())) {
             throw new Resources.NotFoundException("Local Resource Not Found. Resource: '" + getSource() + "'.");
@@ -59,12 +60,11 @@ public class FastImageSource extends ImageSource {

         if (isLocalResourceUri(mUri)) {
             // Convert res:/ scheme to android.resource:// so
-            // glide can understand the uri.
+            // Glide can understand the URI.
             mUri = Uri.parse(mUri.toString().replace("res:/", ANDROID_RESOURCE_SCHEME + "://" + context.getPackageName() + "/"));
         }
     }

-
     public boolean isBase64Resource() {
         return mUri != null && FastImageSource.isBase64Uri(mUri);
     }
@@ -97,7 +97,6 @@ public class FastImageSource extends ImageSource {
         return getGlideUrl();
     }

-    @Override
     public Uri getUri() {
         return mUri;
     }
@@ -109,4 +108,8 @@ public class FastImageSource extends ImageSource {
     public GlideUrl getGlideUrl() {
         return new GlideUrl(getUri().toString(), getHeaders());
     }
+
+    public String getSource() {
+        return imageSource.getSource(); // Delegate to ImageSource
+    }
 }
\ No newline at end of file

This issue body was partially generated by patch-package.

kkkasio commented 2 months ago

desculpe pela pergunta, como posso corrigir o pacote? Você pode me dar instruções, por favor?

Olá! 👋 Primeiramente, obrigado pelo seu trabalho neste projeto! 🙂 Hoje usei o patch-package para aplicar patches react-native-fast-image@8.6.3no projeto no qual estou trabalhando. Aqui está o diff que resolveu meu problema:

diff --git a/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java b/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java
index d9dbd99..1c67401 100644
--- a/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java
+++ b/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java
@@ -11,7 +11,7 @@ import com.facebook.react.views.imagehelper.ImageSource;

 import javax.annotation.Nullable;

-public class FastImageSource extends ImageSource {
+public class FastImageSource {
     private static final String DATA_SCHEME = "data";
     private static final String LOCAL_RESOURCE_SCHEME = "res";
     private static final String ANDROID_RESOURCE_SCHEME = "android.resource";
@@ -19,6 +19,7 @@ public class FastImageSource extends ImageSource {
     private static final String LOCAL_FILE_SCHEME = "file";
     private final Headers mHeaders;
     private Uri mUri;
+    private final ImageSource imageSource; // Composition instead of inheritance

     public static boolean isBase64Uri(Uri uri) {
         return DATA_SCHEME.equals(uri.getScheme());
@@ -49,9 +50,9 @@ public class FastImageSource extends ImageSource {
     }

     public FastImageSource(Context context, String source, double width, double height, @Nullable Headers headers) {
-        super(context, source, width, height);
+        imageSource = new ImageSource(context, source, width, height); // Create ImageSource instance
         mHeaders = headers == null ? Headers.DEFAULT : headers;
-        mUri = super.getUri();
+        mUri = imageSource.getUri(); // Get URI from ImageSource

         if (isResource() && TextUtils.isEmpty(mUri.toString())) {
             throw new Resources.NotFoundException("Local Resource Not Found. Resource: '" + getSource() + "'.");
@@ -59,12 +60,11 @@ public class FastImageSource extends ImageSource {

         if (isLocalResourceUri(mUri)) {
             // Convert res:/ scheme to android.resource:// so
-            // glide can understand the uri.
+            // Glide can understand the URI.
             mUri = Uri.parse(mUri.toString().replace("res:/", ANDROID_RESOURCE_SCHEME + "://" + context.getPackageName() + "/"));
         }
     }

-
     public boolean isBase64Resource() {
         return mUri != null && FastImageSource.isBase64Uri(mUri);
     }
@@ -97,7 +97,6 @@ public class FastImageSource extends ImageSource {
         return getGlideUrl();
     }

-    @Override
     public Uri getUri() {
         return mUri;
     }
@@ -109,4 +108,8 @@ public class FastImageSource extends ImageSource {
     public GlideUrl getGlideUrl() {
         return new GlideUrl(getUri().toString(), getHeaders());
     }
+
+    public String getSource() {
+        return imageSource.getSource(); // Delegate to ImageSource
+    }
 }
\ No newline at end of file

Este corpo de problema foi parcialmente gerado pelo patch-package .

change file in package (react-native-fast-image) from your node_modules folder then run the command

➜ npx patch-package react-native-fast-image --use-yarn

spyshower commented 2 months ago

desculpe pela pergunta, como posso corrigir o pacote? Você pode me dar instruções, por favor?

Olá! 👋 Primeiramente, obrigado pelo seu trabalho neste projeto! 🙂 Hoje usei o patch-package para aplicar patches react-native-fast-image@8.6.3no projeto no qual estou trabalhando. Aqui está o diff que resolveu meu problema:

diff --git a/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java b/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java
index d9dbd99..1c67401 100644
--- a/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java
+++ b/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java
@@ -11,7 +11,7 @@ import com.facebook.react.views.imagehelper.ImageSource;

 import javax.annotation.Nullable;

-public class FastImageSource extends ImageSource {
+public class FastImageSource {
     private static final String DATA_SCHEME = "data";
     private static final String LOCAL_RESOURCE_SCHEME = "res";
     private static final String ANDROID_RESOURCE_SCHEME = "android.resource";
@@ -19,6 +19,7 @@ public class FastImageSource extends ImageSource {
     private static final String LOCAL_FILE_SCHEME = "file";
     private final Headers mHeaders;
     private Uri mUri;
+    private final ImageSource imageSource; // Composition instead of inheritance

     public static boolean isBase64Uri(Uri uri) {
         return DATA_SCHEME.equals(uri.getScheme());
@@ -49,9 +50,9 @@ public class FastImageSource extends ImageSource {
     }

     public FastImageSource(Context context, String source, double width, double height, @Nullable Headers headers) {
-        super(context, source, width, height);
+        imageSource = new ImageSource(context, source, width, height); // Create ImageSource instance
         mHeaders = headers == null ? Headers.DEFAULT : headers;
-        mUri = super.getUri();
+        mUri = imageSource.getUri(); // Get URI from ImageSource

         if (isResource() && TextUtils.isEmpty(mUri.toString())) {
             throw new Resources.NotFoundException("Local Resource Not Found. Resource: '" + getSource() + "'.");
@@ -59,12 +60,11 @@ public class FastImageSource extends ImageSource {

         if (isLocalResourceUri(mUri)) {
             // Convert res:/ scheme to android.resource:// so
-            // glide can understand the uri.
+            // Glide can understand the URI.
             mUri = Uri.parse(mUri.toString().replace("res:/", ANDROID_RESOURCE_SCHEME + "://" + context.getPackageName() + "/"));
         }
     }

-
     public boolean isBase64Resource() {
         return mUri != null && FastImageSource.isBase64Uri(mUri);
     }
@@ -97,7 +97,6 @@ public class FastImageSource extends ImageSource {
         return getGlideUrl();
     }

-    @Override
     public Uri getUri() {
         return mUri;
     }
@@ -109,4 +108,8 @@ public class FastImageSource extends ImageSource {
     public GlideUrl getGlideUrl() {
         return new GlideUrl(getUri().toString(), getHeaders());
     }
+
+    public String getSource() {
+        return imageSource.getSource(); // Delegate to ImageSource
+    }
 }
\ No newline at end of file

Este corpo de problema foi parcialmente gerado pelo patch-package .

change file in package (react-native-fast-image) from your node_modules folder then run the command

➜ npx patch-package react-native-fast-image --use-yarn

if yarn isn't necessary for this, edit your comment and remove it, otherwise you will be messing up with people's environment

deepanshushuklad11 commented 2 months ago

Issue has been fixed in @d11/react-native-fast-image