fix(android): NullPointerException on navigation (#9669)

closes #8441
This commit is contained in:
Osei Fortune
2022-01-23 13:15:10 -04:00
committed by Nathan Walker
parent dbaf203a59
commit 9b5d125f42
4 changed files with 49 additions and 8 deletions

View File

@ -1060,12 +1060,11 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks {
// view.layout(0, 0, width, height);
// view.draw(canvas);
view.setDrawingCacheEnabled(true);
const drawCache = view.getDrawingCache();
const bitmap = android.graphics.Bitmap.createBitmap(drawCache);
view.setDrawingCacheEnabled(false);
return bitmap;
// view.setDrawingCacheEnabled(true);
// const drawCache = view.getDrawingCache();
// const bitmap = android.graphics.Bitmap.createBitmap(drawCache);
// view.setDrawingCacheEnabled(false);
return org.nativescript.widgets.Utils.getBitmapFromView(view);
}
}

View File

@ -633,6 +633,7 @@ declare module org {
export module widgets {
export class Utils {
public static class: java.lang.Class<org.nativescript.widgets.Utils>;
public static getBitmapFromView(param0: globalAndroid.view.View): globalAndroid.graphics.Bitmap;
public static loadImageAsync(param0: globalAndroid.content.Context, param1: string, param2: string, param3: number, param4: number, param5: org.nativescript.widgets.Utils.AsyncImageCallback): void;
public static drawBoxShadow(param0: globalAndroid.view.View, param1: string): void;
public static saveToFileAsync(param0: globalAndroid.graphics.Bitmap, param1: string, param2: string, param3: number, param4: org.nativescript.widgets.Utils.AsyncImageCallback): void;

View File

@ -33,9 +33,14 @@ import java.io.IOException;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import android.graphics.Canvas;
import androidx.core.view.ViewCompat;
import android.os.Build;
public class Utils {
public static Drawable getDrawable(String uri, Context context){
public static Drawable getDrawable(String uri, Context context) {
int resId = 0;
int resPrefixLength = "res://".length();
@ -51,6 +56,42 @@ public class Utils {
return null;
}
}
private static Bitmap drawBitmap(View view) {
int width = view.getWidth();
int height = view.getHeight();
Bitmap bitmap;
if (view.getAlpha() < 1F) {
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
} else {
bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
}
Canvas canvas = new Canvas(bitmap);
if (!ViewCompat.isLaidOut(view)) {
view.layout(0, 0, width, height);
}
view.draw(canvas);
return bitmap;
}
public static Bitmap getBitmapFromView(View view) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
return drawBitmap(view);
} else {
view.setDrawingCacheEnabled(true);
Bitmap drawCache = view.getDrawingCache();
Bitmap bitmap = Bitmap.createBitmap(drawCache);
view.setDrawingCacheEnabled(false);
if (bitmap == null) {
bitmap = drawBitmap(view);
}
return bitmap;
}
}
public static void drawBoxShadow(View view, String value) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.M) {
return;