diff --git a/android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java b/android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java index 61f1971f8..f97ec717a 100644 --- a/android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java +++ b/android/src/main/java/com/dylanvann/fastimage/FastImageViewManager.java @@ -2,6 +2,7 @@ import android.app.Activity; import android.content.Context; +import android.content.ContextWrapper; import android.graphics.PorterDuff; import android.os.Build; @@ -182,32 +183,43 @@ private boolean isNullOrEmpty(final String url) { private static boolean isValidContextForGlide(final Context context) { - if (context == null) { + Activity activity = getActivityFromContext(context); + + if (activity == null) { return false; } + + return !isActivityDestroyed(activity); + } + + private static Activity getActivityFromContext(final Context context) { if (context instanceof Activity) { - final Activity activity = (Activity) context; - if (isActivityDestroyed(activity)) { - return false; - } + return (Activity) context; } if (context instanceof ThemedReactContext) { final Context baseContext = ((ThemedReactContext) context).getBaseContext(); if (baseContext instanceof Activity) { - final Activity baseActivity = (Activity) baseContext; - return !isActivityDestroyed(baseActivity); + return (Activity) baseContext; + } + + if (baseContext instanceof ContextWrapper) { + final ContextWrapper contextWrapper = (ContextWrapper) baseContext; + final Context wrapperBaseContext = contextWrapper.getBaseContext(); + if (wrapperBaseContext instanceof Activity) { + return (Activity) wrapperBaseContext; + } } } - return true; + return null; } private static boolean isActivityDestroyed(Activity activity) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { return activity.isDestroyed() || activity.isFinishing(); } else { - return activity.isFinishing() || activity.isChangingConfigurations(); + return activity.isDestroyed() || activity.isFinishing() || activity.isChangingConfigurations(); } }