Skip to content

Commit 833afe2

Browse files
committed
refactor: check for root view
1 parent d3c29b3 commit 833afe2

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
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: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,7 @@ function initComponentCallbacks() {
418418

419419
if (androidApp.orientation !== newOrientation) {
420420
androidApp.orientation = newOrientation;
421-
if (rootView) {
422-
orientationChanged(rootView, newOrientation);
423-
}
421+
orientationChanged(rootView, newOrientation);
424422

425423
notify(<OrientationChangedEventData>{
426424
eventName: orientationChangedEvent,
@@ -436,9 +434,7 @@ function initComponentCallbacks() {
436434

437435
if (androidApp.systemAppearance !== newSystemAppearance) {
438436
androidApp.systemAppearance = newSystemAppearance;
439-
if (rootView) {
440-
systemAppearanceChanged(rootView, newSystemAppearance);
441-
}
437+
systemAppearanceChanged(rootView, newSystemAppearance);
442438

443439
notify(<SystemAppearanceChangedEventData>{
444440
eventName: systemAppearanceChangedEvent,

0 commit comments

Comments
 (0)