Skip to content

Commit

Permalink
fix RN 0.75.1 ImageSource
Browse files Browse the repository at this point in the history
  • Loading branch information
huextrat committed Aug 19, 2024
1 parent c352f2a commit f7a064b
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions android/src/main/java/com/dylanvann/fastimage/FastImageSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

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";
Expand All @@ -20,6 +20,7 @@ public class FastImageSource extends ImageSource {
private final Headers mHeaders;
private Uri mUri;
private boolean mCacheKeyIgnoreURLParams;
private final ImageSource imageSource; // Composition instead of inheritance

public static boolean isBase64Uri(Uri uri) {
return DATA_SCHEME.equals(uri.getScheme());
Expand Down Expand Up @@ -54,9 +55,9 @@ public FastImageSource(Context context, String source, @Nullable Headers headers
}

public FastImageSource(Context context, String source, double width, double height, @Nullable Headers headers, boolean cacheKeyIgnoreURLParams) {
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
mCacheKeyIgnoreURLParams = cacheKeyIgnoreURLParams;

if (isResource() && TextUtils.isEmpty(mUri.toString())) {
Expand All @@ -65,12 +66,11 @@ public FastImageSource(Context context, String source, double width, double heig

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);
}
Expand Down Expand Up @@ -103,7 +103,6 @@ public Object getSourceForLoad() {
return getGlideUrl();
}

@Override
public Uri getUri() {
return mUri;
}
Expand All @@ -118,4 +117,8 @@ public GlideUrl getGlideUrl() {
}
return new GlideUrl(getUri().toString(), getHeaders());
}
}

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

0 comments on commit f7a064b

Please sign in to comment.