diff --git a/nativescript-core/ui/core/view/view.android.ts b/nativescript-core/ui/core/view/view.android.ts index b11f7d73b..244edad35 100644 --- a/nativescript-core/ui/core/view/view.android.ts +++ b/nativescript-core/ui/core/view/view.android.ts @@ -155,6 +155,8 @@ function initializeDialogFragment() { const ownerId = this.getArguments().getInt(DOMID); const options = getModalOptions(ownerId); this.owner = options.owner; + // Set owner._dialogFragment to this in case the DialogFragment was recreated after app suspend + this.owner._dialogFragment = this; this._fullscreen = options.fullscreen; this._animated = options.animated; this._cancelable = options.cancelable; diff --git a/nativescript-core/ui/frame/frame.android.ts b/nativescript-core/ui/frame/frame.android.ts index 286575b3c..e8f798f28 100644 --- a/nativescript-core/ui/frame/frame.android.ts +++ b/nativescript-core/ui/frame/frame.android.ts @@ -264,13 +264,13 @@ export class Frame extends FrameBase { !this._currentEntry.fragment.isAdded()) { return; } + const fragment: androidx.fragment.app.Fragment = this._currentEntry.fragment; + const fragmentManager: androidx.fragment.app.FragmentManager = fragment.getFragmentManager(); - const manager: androidx.fragment.app.FragmentManager = this._getFragmentManager(); - const transaction = manager.beginTransaction(); - const fragment = this._currentEntry.fragment; + const transaction = fragmentManager.beginTransaction(); const fragmentExitTransition = fragment.getExitTransition(); - // Reset animation to its initial state to prevent mirrorered effect when restore current fragment transitions + // Reset animation to its initial state to prevent mirrored effect when restore current fragment transitions if (fragmentExitTransition && fragmentExitTransition instanceof org.nativescript.widgets.CustomTransition) { fragmentExitTransition.setResetOnTransitionEnd(true); } @@ -637,7 +637,7 @@ function clearEntry(entry: BackstackEntry): void { entry.recreated = false; entry.fragment = null; const page = entry.resolvedPage; - if (page._context) { + if (page && page._context) { entry.resolvedPage._tearDownUI(true); } } @@ -1032,6 +1032,12 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks { } private loadBitmapFromView(view: android.view.View): android.graphics.Bitmap { + // Don't try to creat bitmaps with no dimensions as this causes a crash + // This might happen when showing and closing dialogs fast. + if (!(view && view.getWidth() > 0 && view.getHeight() > 0)) { + return undefined; + } + // Another way to get view bitmap. Test performance vs setDrawingCacheEnabled // const width = view.getWidth(); // const height = view.getHeight(); @@ -1041,7 +1047,8 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks { // view.draw(canvas); view.setDrawingCacheEnabled(true); - const bitmap = android.graphics.Bitmap.createBitmap(view.getDrawingCache()); + const drawCache = view.getDrawingCache(); + const bitmap = android.graphics.Bitmap.createBitmap(drawCache); view.setDrawingCacheEnabled(false); return bitmap; diff --git a/nativescript-core/utils/utils.ios.ts b/nativescript-core/utils/utils.ios.ts index 17474fd8d..c01e04f39 100644 --- a/nativescript-core/utils/utils.ios.ts +++ b/nativescript-core/utils/utils.ios.ts @@ -6,8 +6,6 @@ import { export { ios }; export * from "./utils-common"; -let mainScreenScale; - export function openFile(filePath: string): boolean { try { const appPath = ios.getCurrentAppPath(); @@ -47,5 +45,3 @@ export function openUrl(location: string): boolean { return false; } - -mainScreenScale = UIScreen.mainScreen.scale;