Skip to content

Commit 135aeff

Browse files
vchimevmanoldonev
authored andcommitted
fix(android): check for root view on configuration changed (#7944)
1 parent 08e23bc commit 135aeff

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

tns-core-modules/application/application-common.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ function removeCssClass(rootView: View, cssClass: string) {
143143
}
144144

145145
export function orientationChanged(rootView: View, newOrientation: "portrait" | "landscape" | "unknown"): void {
146+
if (!rootView) {
147+
return;
148+
}
149+
146150
const newOrientationCssClass = `${CLASS_PREFIX}${newOrientation}`;
147151
if (!rootView.cssClasses.has(newOrientationCssClass)) {
148152
ORIENTATION_CSS_CLASSES.forEach(cssClass => removeCssClass(rootView, cssClass));
@@ -152,6 +156,10 @@ export function orientationChanged(rootView: View, newOrientation: "portrait" |
152156
}
153157

154158
export function systemAppearanceChanged(rootView: View, newSystemAppearance: "dark" | "light"): void {
159+
if (!rootView) {
160+
return;
161+
}
162+
155163
const newSystemAppearanceCssClass = `${CLASS_PREFIX}${newSystemAppearance}`;
156164
if (!rootView.cssClasses.has(newSystemAppearanceCssClass)) {
157165
SYSTEM_APPEARANCE_CSS_CLASSES.forEach(cssClass => removeCssClass(rootView, cssClass));

tns-core-modules/application/application.android.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,11 +413,12 @@ function initComponentCallbacks() {
413413
}),
414414

415415
onConfigurationChanged: profile("onConfigurationChanged", function (newConfiguration: android.content.res.Configuration) {
416+
const rootView = getRootView();
416417
const newOrientation = getOrientationValue(newConfiguration);
417418

418419
if (androidApp.orientation !== newOrientation) {
419420
androidApp.orientation = newOrientation;
420-
orientationChanged(getRootView(), newOrientation);
421+
orientationChanged(rootView, newOrientation);
421422

422423
notify(<OrientationChangedEventData>{
423424
eventName: orientationChangedEvent,
@@ -433,7 +434,7 @@ function initComponentCallbacks() {
433434

434435
if (androidApp.systemAppearance !== newSystemAppearance) {
435436
androidApp.systemAppearance = newSystemAppearance;
436-
systemAppearanceChanged(getRootView(), newSystemAppearance);
437+
systemAppearanceChanged(rootView, newSystemAppearance);
437438

438439
notify(<SystemAppearanceChangedEventData>{
439440
eventName: systemAppearanceChangedEvent,

0 commit comments

Comments
 (0)