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 78b3773
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions android/src/main/java/com/dylanvann/fastimage/FastImageSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

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 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 All @@ -46,31 +46,25 @@ public FastImageSource(Context context, String source) {
}

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

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

public FastImageSource(Context context, String source, double width, double height, @Nullable Headers headers, boolean cacheKeyIgnoreURLParams) {
super(context, source, width, height);
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 = super.getUri();
mCacheKeyIgnoreURLParams = cacheKeyIgnoreURLParams;
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.
// 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 +97,6 @@ public Object getSourceForLoad() {
return getGlideUrl();
}

@Override
public Uri getUri() {
return mUri;
}
Expand All @@ -113,9 +106,10 @@ public Headers getHeaders() {
}

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

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

0 comments on commit 78b3773

Please sign in to comment.