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

Fix: Ensure react-native-fast-image compatibility with RN 0.75.2 #1050

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions android/src/main/java/com/dylanvann/fastimage/FastImageSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@

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 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";
private static final String ANDROID_CONTENT_SCHEME = "content";
private static final String LOCAL_FILE_SCHEME = "file";

private final String mSource;
private final double mWidth;
private final double mHeight;
private final Headers mHeaders;
private Uri mUri;

Expand All @@ -41,20 +44,23 @@ public static boolean isLocalFileUri(Uri uri) {
}

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

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

public FastImageSource(Context context, String source, double width, double height, @Nullable Headers headers) {
super(context, source, width, height);
public FastImageSource(Context context, String source, @Nullable Headers headers, double width, double height) {
mSource = source;
mWidth = width;
mHeight = height;
mHeaders = headers == null ? Headers.DEFAULT : headers;
mUri = super.getUri();

mUri = Uri.parse(source);

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

if (isLocalResourceUri(mUri)) {
Expand All @@ -64,7 +70,6 @@ public FastImageSource(Context context, String source, double width, double heig
}
}


public boolean isBase64Resource() {
return mUri != null && FastImageSource.isBase64Uri(mUri);
}
Expand All @@ -83,10 +88,10 @@ public boolean isContentUri() {

public Object getSourceForLoad() {
if (isContentUri()) {
return getSource();
return mSource;
}
if (isBase64Resource()) {
return getSource();
return mSource;
}
if (isResource()) {
return getUri();
Expand All @@ -97,7 +102,6 @@ public Object getSourceForLoad() {
return getGlideUrl();
}

@Override
public Uri getUri() {
return mUri;
}
Expand All @@ -109,4 +113,16 @@ public Headers getHeaders() {
public GlideUrl getGlideUrl() {
return new GlideUrl(getUri().toString(), getHeaders());
}

public String getSource() {
return mSource;
}

public double getWidth() {
return mWidth;
}

public double getHeight() {
return mHeight;
}
}