From d3c29b31dee0c85be38d7fde64c373db1a5753de Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Fri, 11 Oct 2019 11:23:02 +0300 Subject: [PATCH 1/2] fix(android): check for root view on configuration changed A Playground and Preview apps scenario. --- tns-core-modules/application/application.android.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tns-core-modules/application/application.android.ts b/tns-core-modules/application/application.android.ts index e7c1592837..7a4d8eab97 100644 --- a/tns-core-modules/application/application.android.ts +++ b/tns-core-modules/application/application.android.ts @@ -413,11 +413,14 @@ function initComponentCallbacks() { }), onConfigurationChanged: profile("onConfigurationChanged", function (newConfiguration: android.content.res.Configuration) { + const rootView = getRootView(); const newOrientation = getOrientationValue(newConfiguration); if (androidApp.orientation !== newOrientation) { androidApp.orientation = newOrientation; - orientationChanged(getRootView(), newOrientation); + if (rootView) { + orientationChanged(rootView, newOrientation); + } notify({ eventName: orientationChangedEvent, @@ -433,7 +436,9 @@ function initComponentCallbacks() { if (androidApp.systemAppearance !== newSystemAppearance) { androidApp.systemAppearance = newSystemAppearance; - systemAppearanceChanged(getRootView(), newSystemAppearance); + if (rootView) { + systemAppearanceChanged(rootView, newSystemAppearance); + } notify({ eventName: systemAppearanceChangedEvent, From 833afe245a53048b0fc333bfbbe1c4e8c85c93d2 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Mon, 14 Oct 2019 13:36:43 +0300 Subject: [PATCH 2/2] refactor: check for root view --- tns-core-modules/application/application-common.ts | 8 ++++++++ tns-core-modules/application/application.android.ts | 8 ++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tns-core-modules/application/application-common.ts b/tns-core-modules/application/application-common.ts index cdce188f54..536013ed4a 100644 --- a/tns-core-modules/application/application-common.ts +++ b/tns-core-modules/application/application-common.ts @@ -143,6 +143,10 @@ function removeCssClass(rootView: View, cssClass: string) { } export function orientationChanged(rootView: View, newOrientation: "portrait" | "landscape" | "unknown"): void { + if (!rootView) { + return; + } + const newOrientationCssClass = `${CLASS_PREFIX}${newOrientation}`; if (!rootView.cssClasses.has(newOrientationCssClass)) { ORIENTATION_CSS_CLASSES.forEach(cssClass => removeCssClass(rootView, cssClass)); @@ -152,6 +156,10 @@ export function orientationChanged(rootView: View, newOrientation: "portrait" | } export function systemAppearanceChanged(rootView: View, newSystemAppearance: "dark" | "light"): void { + if (!rootView) { + return; + } + const newSystemAppearanceCssClass = `${CLASS_PREFIX}${newSystemAppearance}`; if (!rootView.cssClasses.has(newSystemAppearanceCssClass)) { SYSTEM_APPEARANCE_CSS_CLASSES.forEach(cssClass => removeCssClass(rootView, cssClass)); diff --git a/tns-core-modules/application/application.android.ts b/tns-core-modules/application/application.android.ts index 7a4d8eab97..b14ac16325 100644 --- a/tns-core-modules/application/application.android.ts +++ b/tns-core-modules/application/application.android.ts @@ -418,9 +418,7 @@ function initComponentCallbacks() { if (androidApp.orientation !== newOrientation) { androidApp.orientation = newOrientation; - if (rootView) { - orientationChanged(rootView, newOrientation); - } + orientationChanged(rootView, newOrientation); notify({ eventName: orientationChangedEvent, @@ -436,9 +434,7 @@ function initComponentCallbacks() { if (androidApp.systemAppearance !== newSystemAppearance) { androidApp.systemAppearance = newSystemAppearance; - if (rootView) { - systemAppearanceChanged(rootView, newSystemAppearance); - } + systemAppearanceChanged(rootView, newSystemAppearance); notify({ eventName: systemAppearanceChangedEvent,