|
2 | 2 |
|
3 | 3 | import android.app.Activity;
|
4 | 4 | import android.content.Context;
|
| 5 | +import android.content.ContextWrapper; |
5 | 6 | import android.graphics.PorterDuff;
|
6 | 7 | import android.os.Build;
|
7 | 8 |
|
@@ -182,32 +183,43 @@ private boolean isNullOrEmpty(final String url) {
|
182 | 183 |
|
183 | 184 |
|
184 | 185 | private static boolean isValidContextForGlide(final Context context) {
|
185 |
| - if (context == null) { |
| 186 | + Activity activity = getActivityFromContext(context); |
| 187 | + |
| 188 | + if (activity == null) { |
186 | 189 | return false;
|
187 | 190 | }
|
| 191 | + |
| 192 | + return !isActivityDestroyed(activity); |
| 193 | + } |
| 194 | + |
| 195 | + private static Activity getActivityFromContext(final Context context) { |
188 | 196 | if (context instanceof Activity) {
|
189 |
| - final Activity activity = (Activity) context; |
190 |
| - if (isActivityDestroyed(activity)) { |
191 |
| - return false; |
192 |
| - } |
| 197 | + return (Activity) context; |
193 | 198 | }
|
194 | 199 |
|
195 | 200 | if (context instanceof ThemedReactContext) {
|
196 | 201 | final Context baseContext = ((ThemedReactContext) context).getBaseContext();
|
197 | 202 | if (baseContext instanceof Activity) {
|
198 |
| - final Activity baseActivity = (Activity) baseContext; |
199 |
| - return !isActivityDestroyed(baseActivity); |
| 203 | + return (Activity) baseContext; |
| 204 | + } |
| 205 | + |
| 206 | + if (baseContext instanceof ContextWrapper) { |
| 207 | + final ContextWrapper contextWrapper = (ContextWrapper) baseContext; |
| 208 | + final Context wrapperBaseContext = contextWrapper.getBaseContext(); |
| 209 | + if (wrapperBaseContext instanceof Activity) { |
| 210 | + return (Activity) wrapperBaseContext; |
| 211 | + } |
200 | 212 | }
|
201 | 213 | }
|
202 | 214 |
|
203 |
| - return true; |
| 215 | + return null; |
204 | 216 | }
|
205 | 217 |
|
206 | 218 | private static boolean isActivityDestroyed(Activity activity) {
|
207 | 219 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
208 | 220 | return activity.isDestroyed() || activity.isFinishing();
|
209 | 221 | } else {
|
210 |
| - return activity.isFinishing() || activity.isChangingConfigurations(); |
| 222 | + return activity.isDestroyed() || activity.isFinishing() || activity.isChangingConfigurations(); |
211 | 223 | }
|
212 | 224 |
|
213 | 225 | }
|
|
0 commit comments