From 1f1d72200855d318bdce78ad7b61f27818183354 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Tue, 8 Jan 2019 21:03:28 +0200 Subject: [PATCH] fix(Android): a crash on application restart after livesync changes (#6756) ``` An uncaught Exception occurred on "main" thread. com.tns.NativeScriptException: Calling js method run failed TypeError: Cannot read property 'getRootView' of undefined File: file:///data/data/org.nativescript.preview/files/app/tns_modules/tns-core-modules/ui/frame/frame.js, line: 56, column:29 ``` --- tns-core-modules/ui/frame/frame.android.ts | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tns-core-modules/ui/frame/frame.android.ts b/tns-core-modules/ui/frame/frame.android.ts index 4053b9890..fdde423ab 100644 --- a/tns-core-modules/ui/frame/frame.android.ts +++ b/tns-core-modules/ui/frame/frame.android.ts @@ -85,10 +85,14 @@ function getAttachListener(): android.view.View.OnAttachStateChangeListener { export function reloadPage(): void { const activity = application.android.foregroundActivity; const callbacks: AndroidActivityCallbacks = activity[CALLBACKS]; - const rootView: View = callbacks.getRootView(); + if (callbacks) { + const rootView: View = callbacks.getRootView(); - if (!rootView || !rootView._onLivesync()) { - callbacks.resetActivityContent(activity); + if (!rootView || !rootView._onLivesync()) { + callbacks.resetActivityContent(activity); + } + } else { + traceError(`${activity}[CALLBACKS] is null or undefined`); } } @@ -469,19 +473,19 @@ export class Frame extends FrameBase { switch (this.actionBarVisibility) { case "never": return false; - + case "always": return true; - + default: if (page.actionBarHidden !== undefined) { return !page.actionBarHidden; } - + if (this._android && this._android.showActionBar !== undefined) { return this._android.showActionBar; } - + return true; } } @@ -530,7 +534,7 @@ function restoreAnimatorState(entry: BackstackEntry, snapshot: AnimatorState): v if (snapshot.enterAnimator) { expandedEntry.enterAnimator = snapshot.enterAnimator; } - + if (snapshot.exitAnimator) { expandedEntry.exitAnimator = snapshot.exitAnimator; } @@ -538,7 +542,7 @@ function restoreAnimatorState(entry: BackstackEntry, snapshot: AnimatorState): v if (snapshot.popEnterAnimator) { expandedEntry.popEnterAnimator = snapshot.popEnterAnimator; } - + if (snapshot.popExitAnimator) { expandedEntry.popExitAnimator = snapshot.popExitAnimator; } @@ -858,7 +862,7 @@ class FragmentCallbacksImplementation implements AndroidFragmentCallbacks { // parent while its supposed parent believes it properly removed its children; in order to "force" the child to // lose its parent we temporarily add it to the parent, and then remove it (addViewInLayout doesn't trigger layout pass) const nativeView = page.nativeViewProtected; - if (nativeView != null) { + if (nativeView != null) { const parentView = nativeView.getParent(); if (parentView instanceof android.view.ViewGroup) { if (parentView.getChildCount() === 0) {