package com.reactnativenavigation.react;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.StrictMode;
import android.support.annotation.NonNull;

import com.reactnativenavigation.NavigationApplication;

import java.io.IOException;
import java.net.URL;

public class JsDevImageLoader {

    public static Drawable loadIcon(String iconDevUri) {
        try {
            StrictMode.ThreadPolicy threadPolicy = StrictMode.getThreadPolicy();
            StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitNetwork().build());

            Drawable drawable = tryLoadIcon(iconDevUri);

            StrictMode.setThreadPolicy(threadPolicy);
            return drawable;
        } catch (Exception e) {
            throw new RuntimeException(iconDevUri, e);
        }
    }

    @NonNull
    private static Drawable tryLoadIcon(String iconDevUri) throws IOException {
        URL url = new URL(iconDevUri);
        Bitmap bitmap = BitmapFactory.decodeStream(url.openStream());
        return new BitmapDrawable(NavigationApplication.instance.getResources(), bitmap);
    }
}

@@ -270,16 +270,41 @@
 NonNull;
+%0Aimport android.util.Log;
 %0A%0Aimport
@@ -436,16 +436,73 @@
 oader %7B%0A
+    private static final String TAG = %22JsDevImageLoader%22;
 %0A    pub
@@ -939,48 +939,96 @@
     
-throw new RuntimeException(iconDevUri, e
+Log.e(TAG, %22Unable to load icon: %22 + iconDevUri);%0A            return new BitmapDrawable(
 );%0A 

Return empty Drawable when bridge isn't available (#1360)