Fix android photo library images not working. (#339)

This commit is contained in:
Dylan Vann 2018-11-06 01:07:28 -05:00 committed by GitHub
parent 01dac3b745
commit f8606a1f2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 9 deletions

View File

@ -2,7 +2,6 @@ package com.dylanvann.fastimage;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.Headers;
@ -11,19 +10,29 @@ import com.facebook.react.views.imagehelper.ImageSource;
import javax.annotation.Nullable;
public class FastImageSource extends ImageSource {
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 Headers mHeaders;
private Uri mUri;
public static boolean isLocalResourceUri (Uri uri) {
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) {
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 FastImageSource(Context context, String source) {
this(context, source, null);
}
@ -45,8 +54,30 @@ public class FastImageSource extends ImageSource {
}
}
public boolean isBase64Resource () {
return mUri != null && "data".equals(mUri.getScheme());
public boolean isBase64Resource() {
return mUri != null && FastImageSource.isBase64Uri(mUri);
}
public boolean isResource() {
return mUri != null && FastImageSource.isResourceUri(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();
}
return getGlideUrl();
}
@Override

View File

@ -101,10 +101,7 @@ class FastImageViewManager extends SimpleViewManager<FastImageViewWithUrl> imple
// - res:/
// - android.resource://
// - data:image/png;base64
.load(
imageSource.isBase64Resource() ? imageSource.getSource() :
imageSource.isResource() ? imageSource.getUri() : imageSource.getGlideUrl()
)
.load(imageSource.getSourceForLoad())
.apply(FastImageViewConverter.getOptions(source))
.listener(new FastImageRequestListener(key))
.into(view);