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 e7c1592837..b14ac16325 100644 --- a/tns-core-modules/application/application.android.ts +++ b/tns-core-modules/application/application.android.ts @@ -413,11 +413,12 @@ 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); + orientationChanged(rootView, newOrientation); notify({ eventName: orientationChangedEvent, @@ -433,7 +434,7 @@ function initComponentCallbacks() { if (androidApp.systemAppearance !== newSystemAppearance) { androidApp.systemAppearance = newSystemAppearance; - systemAppearanceChanged(getRootView(), newSystemAppearance); + systemAppearanceChanged(rootView, newSystemAppearance); notify({ eventName: systemAppearanceChangedEvent,