Code Monkey home page Code Monkey logo

Comments (27)

Boscotec avatar Boscotec commented on August 28, 2024 18

Temporary Workaround.

You can try modifying the library code until the library is officially updated.

Open the file causing issues: /node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java.

Replace the code with the one below.

package com.dylanvann.fastimage;

import android.content.Context;
import android.content.res.Resources;
import android.net.Uri;
import android.text.TextUtils;

import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.Headers;
import com.facebook.react.views.imagehelper.ImageSource;

import javax.annotation.Nullable;

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";
    private static final String ANDROID_CONTENT_SCHEME = "content";
    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());
    }

    public static boolean isLocalResourceUri(Uri uri) {
        return LOCAL_RESOURCE_SCHEME.equals(uri.getScheme());
    }

    public static boolean isResourceUri(Uri uri) {
        return ANDROID_RESOURCE_SCHEME.equals(uri.getScheme());
    }

    public static boolean isContentUri(Uri uri) {
        return ANDROID_CONTENT_SCHEME.equals(uri.getScheme());
    }

    public static boolean isLocalFileUri(Uri uri) {
        return LOCAL_FILE_SCHEME.equals(uri.getScheme());
    }

    public FastImageSource(Context context, String source) {
        this(context, source, null);
    }

    public FastImageSource(Context context, String source, @Nullable Headers headers) {
        this(context, source, 0.0d, 0.0d, headers);
    }

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

        if (isResource() && TextUtils.isEmpty(mUri.toString())) {
            throw new Resources.NotFoundException("Local Resource Not Found. Resource: '" + getSource() + "'.");
        }

        if (isLocalResourceUri(mUri)) {
            // Convert res:/ scheme to android.resource:// so
            // 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);
    }

    public boolean isResource() {
        return mUri != null && FastImageSource.isResourceUri(mUri);
    }

    public boolean isLocalFile() {
        return mUri != null && FastImageSource.isLocalFileUri(mUri);
    }

    public boolean isContentUri() {
        return mUri != null && FastImageSource.isContentUri(mUri);
    }

    public Object getSourceForLoad() {
        if (isContentUri()) {
            return getSource();
        }
        if (isBase64Resource()) {
            return getSource();
        }
        if (isResource()) {
            return getUri();
        }
        if (isLocalFile()) {
            return getUri().toString();
        }
        return getGlideUrl();
    }

    public Uri getUri() {
        return mUri;
    }

    public Headers getHeaders() {
        return mHeaders;
    }

    public GlideUrl getGlideUrl() {
        return new GlideUrl(getUri().toString(), getHeaders());
    }

    public String getSource() {
        return imageSource.getSource(); // Delegate to ImageSource
    }
}

Finally you can use patch package (https://github.com/ds300/patch-package) to patch it.

from react-native-fast-image.

deepanshushuklad11 avatar deepanshushuklad11 commented on August 28, 2024 8

Hello use https://www.npmjs.com/package/@d11/react-native-fast-image
It is actively maintained and issue will be resolved soon

from react-native-fast-image.

divyangkhatri avatar divyangkhatri commented on August 28, 2024 6

same here

from react-native-fast-image.

Kolahzary avatar Kolahzary commented on August 28, 2024 6

This PR on react-native will solve this issue:

from react-native-fast-image.

Koykoy200078 avatar Koykoy200078 commented on August 28, 2024 5

same issue

from react-native-fast-image.

ahmaddehnavi avatar ahmaddehnavi commented on August 28, 2024 4

Same here

from react-native-fast-image.

NensiKasundra avatar NensiKasundra commented on August 28, 2024 4

it's not working with 0.75.2 also

from react-native-fast-image.

ramonxm avatar ramonxm commented on August 28, 2024 3

0.75.2 is fixed this issues

not fixed for me

from react-native-fast-image.

NensiKasundra avatar NensiKasundra commented on August 28, 2024 3

Getting below errors with 0.75.2 version

/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java:72: error: isResource() in FastImageSource cannot override isResource() in ImageSource
public boolean isResource() {
^
overridden method is final

/node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java:101: error: getUri() in FastImageSource cannot override getUri() in ImageSource
public Uri getUri() {
^
overridden method is final

from react-native-fast-image.

mohsenfl2022 avatar mohsenfl2022 commented on August 28, 2024 2

I am also getting the same issue. I am using the latest 0.75.1 version of the React Native library. Please heeeeeeeeeeeeeelp!

from react-native-fast-image.

hpanwar521 avatar hpanwar521 commented on August 28, 2024 1

I am also getting the same issue, i am using latest 0.75.1 version of react native library

from react-native-fast-image.

ramonxm avatar ramonxm commented on August 28, 2024

same here, any solutions?

from react-native-fast-image.

aviral1518 avatar aviral1518 commented on August 28, 2024

same here, any solutions?

from react-native-fast-image.

aviral1518 avatar aviral1518 commented on August 28, 2024

Temporary Workaround.

You can try modifying the library code until the library is officially updated.

Open the file causing issues: /node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java.

Replace the code with the one below.

package com.dylanvann.fastimage;

import android.content.Context;
import android.content.res.Resources;
import android.net.Uri;
import android.text.TextUtils;

import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.Headers;
import com.facebook.react.views.imagehelper.ImageSource;

import javax.annotation.Nullable;

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";
    private static final String ANDROID_CONTENT_SCHEME = "content";
    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());
    }

    public static boolean isLocalResourceUri(Uri uri) {
        return LOCAL_RESOURCE_SCHEME.equals(uri.getScheme());
    }

    public static boolean isResourceUri(Uri uri) {
        return ANDROID_RESOURCE_SCHEME.equals(uri.getScheme());
    }

    public static boolean isContentUri(Uri uri) {
        return ANDROID_CONTENT_SCHEME.equals(uri.getScheme());
    }

    public static boolean isLocalFileUri(Uri uri) {
        return LOCAL_FILE_SCHEME.equals(uri.getScheme());
    }

    public FastImageSource(Context context, String source) {
        this(context, source, null);
    }

    public FastImageSource(Context context, String source, @Nullable Headers headers) {
        this(context, source, 0.0d, 0.0d, headers);
    }

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

        if (isResource() && TextUtils.isEmpty(mUri.toString())) {
            throw new Resources.NotFoundException("Local Resource Not Found. Resource: '" + getSource() + "'.");
        }

        if (isLocalResourceUri(mUri)) {
            // Convert res:/ scheme to android.resource:// so
            // 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);
    }

    public boolean isResource() {
        return mUri != null && FastImageSource.isResourceUri(mUri);
    }

    public boolean isLocalFile() {
        return mUri != null && FastImageSource.isLocalFileUri(mUri);
    }

    public boolean isContentUri() {
        return mUri != null && FastImageSource.isContentUri(mUri);
    }

    public Object getSourceForLoad() {
        if (isContentUri()) {
            return getSource();
        }
        if (isBase64Resource()) {
            return getSource();
        }
        if (isResource()) {
            return getUri();
        }
        if (isLocalFile()) {
            return getUri().toString();
        }
        return getGlideUrl();
    }

    public Uri getUri() {
        return mUri;
    }

    public Headers getHeaders() {
        return mHeaders;
    }

    public GlideUrl getGlideUrl() {
        return new GlideUrl(getUri().toString(), getHeaders());
    }

    public String getSource() {
        return imageSource.getSource(); // Delegate to ImageSource
    }
}

Finally you can use patch package (https://github.com/ds300/patch-package) to patch it.

@hpanwar521 try this solution. It will work.

from react-native-fast-image.

hpanwar521 avatar hpanwar521 commented on August 28, 2024

This is also not working for me ... is there any other solution

from react-native-fast-image.

aviral1518 avatar aviral1518 commented on August 28, 2024

I am also getting the same issue. I am using the latest 0.75.1 version of the React Native library. Please heeeeeeeeeeeeeelp!

@mohsenfl2022 follow these steps:-

  1. Put the attached patch file inside the patches folder. If there is no patches folder, create one and put that file
image
  1. Install patch-package.

  2. After installation, run npx patch-package react-native-fast-image.

After that try building the app. It will work fine

react-native-fast-image+8.6.3.patch

from react-native-fast-image.

NensiKasundra avatar NensiKasundra commented on August 28, 2024

facing the same issue with react-native 0.75.1 version while running the application in android.

node_modules/react-native-fast-image/android/src/main/java/com/dylanvann/fastimage/FastImageSource.java:14: error: cannot inherit from final ImageSource
public class FastImageSource extends ImageSource {
^

@DylanVann Kindly look into this

from react-native-fast-image.

deepanshushuklad11 avatar deepanshushuklad11 commented on August 28, 2024

This is fixed in https://github.com/facebook/react-native/pull/46092/files
You can also try @d11/react-native-fast-image

from react-native-fast-image.

NensiKasundra avatar NensiKasundra commented on August 28, 2024

it's a fork of this. can we upgrade this in the same?

from react-native-fast-image.

deepanshushuklad11 avatar deepanshushuklad11 commented on August 28, 2024

it's a fork of this. can we upgrade this in the same?

react-native is the peer dependency of react-native-fast-image. So when you upgrade your app to the fixed version of react-native , it will automatically work

from react-native-fast-image.

NensiKasundra avatar NensiKasundra commented on August 28, 2024

Here are the versions of libs. still, it's not working.

    "react": "18.3.1",
    "react-native": "0.75.1",
    "react-native-fast-image": "^8.6.3",

from react-native-fast-image.

hamdij0maa avatar hamdij0maa commented on August 28, 2024

+1

from react-native-fast-image.

gonzalorocha avatar gonzalorocha commented on August 28, 2024

+1

from react-native-fast-image.

SpawN005 avatar SpawN005 commented on August 28, 2024

+1

from react-native-fast-image.

liptonzuma avatar liptonzuma commented on August 28, 2024

Any progress on this fam

from react-native-fast-image.

kodeandoec avatar kodeandoec commented on August 28, 2024

Someone have a solution for this issue, can someone contact with the repo owner?

from react-native-fast-image.

kodeandoec avatar kodeandoec commented on August 28, 2024

There's also a new alternative, Faster Image, https://github.com/candlefinance/faster-image

from react-native-fast-image.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.