Skip to content

Commit

Permalink
fix: local image loading issue in debug and release app (#77)
Browse files Browse the repository at this point in the history
* fix: local image loading issue  in debug and release app

* fix: local image loading issue  in debug and release app

* fix: local image loading issue  in debug and release app

* fix: local image loading issue  in debug and release app

* fix: local image loading issue  in debug and release app
  • Loading branch information
deepanshushuklad11 committed Sep 23, 2024
1 parent d36e230 commit cbbc806
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
42 changes: 14 additions & 28 deletions android/src/main/java/com/dylanvann/fastimage/FastImageSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

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;

Expand All @@ -16,11 +17,9 @@ public class FastImageSource {
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;
private String mSource;

public static boolean isBase64Uri(Uri uri) {
return DATA_SCHEME.equals(uri.getScheme());
Expand All @@ -43,22 +42,21 @@ public static boolean isLocalFileUri(Uri uri) {
}

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

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

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

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

if (isLocalResourceUri(mUri)) {
Expand Down Expand Up @@ -87,21 +85,17 @@ public boolean isContentUri() {

public Object getSourceForLoad() {
if (isContentUri() || isBase64Resource()) {
return mSource;
return getSource();
}
if (isResource()) {

if (isResource() || isLocalFile()) {
return getUri();
}
if (isLocalFile()) {
return getUri().toString();
}

return getGlideUrl();
}

public Uri getUri() {
if (mUri == null) {
throw new IllegalStateException("URI is null for the source: " + mSource);
}
return mUri;
}

Expand All @@ -114,14 +108,6 @@ public GlideUrl getGlideUrl() {
}

public String getSource() {
return mSource;
}

public double getWidth() {
return mWidth;
}

public double getHeight() {
return mHeight;
return mSource // Delegate to ImageSource
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void onAfterUpdate(

// Clear the image.
setImageDrawable(null);

ThemedReactContext context = (ThemedReactContext) getContext();
EventDispatcher dispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, getId());
int surfaceId = UIManagerHelper.getSurfaceId(this);
Expand Down

0 comments on commit cbbc806

Please sign in to comment.