Skip to content

Commit beca1c8

Browse files
vchimevmanoldonev
authored andcommitted
fix-next(iOS): set root viewe css classes before setup UI (#8005)
At application launch, `ns-root` class is not set when loading the theme.
1 parent c9bfec1 commit beca1c8

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

nativescript-core/application/application.ios.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import { Builder } from "../ui/builder";
2222
import {
2323
CLASS_PREFIX,
2424
getRootViewCssClasses,
25-
pushToRootViewCssClasses,
26-
resetRootViewCssClasses
25+
pushToRootViewCssClasses
2726
} from "../css/system-classes";
2827

2928
import { ios as iosView, View } from "../ui/core/view";
@@ -308,7 +307,7 @@ class IOSApplication implements IOSApplicationDefinition {
308307
this._window.makeKeyAndVisible();
309308
}
310309

311-
setupRootViewCssClasses(rootView);
310+
setRootViewSystemAppearanceCssClass(rootView);
312311
rootView.on(iosView.traitCollectionColorAppearanceChangedEvent, () => {
313312
const userInterfaceStyle = controller.traitCollection.userInterfaceStyle;
314313
const newSystemAppearance = getSystemAppearanceValue(userInterfaceStyle);
@@ -356,6 +355,8 @@ function createRootView(v?: View) {
356355
}
357356
}
358357

358+
setRootViewCssClasses(rootView);
359+
359360
return rootView;
360361
}
361362

@@ -398,7 +399,7 @@ export function _start(entry?: string | NavigationEntry) {
398399

399400
// Mind root view CSS classes in future work
400401
// on embedding NativeScript applications
401-
setupRootViewCssClasses(rootView);
402+
setRootViewSystemAppearanceCssClass(rootView);
402403
rootView.on(iosView.traitCollectionColorAppearanceChangedEvent, () => {
403404
const userInterfaceStyle = controller.traitCollection.userInterfaceStyle;
404405
const newSystemAppearance = getSystemAppearanceValue(userInterfaceStyle);
@@ -482,22 +483,24 @@ function setViewControllerView(view: View): void {
482483
}
483484
}
484485

485-
function setupRootViewCssClasses(rootView: View): void {
486-
resetRootViewCssClasses();
487-
486+
function setRootViewCssClasses(rootView: View): void {
488487
const deviceType = device.deviceType.toLowerCase();
489488
pushToRootViewCssClasses(`${CLASS_PREFIX}${IOS_PLATFORM}`);
490489
pushToRootViewCssClasses(`${CLASS_PREFIX}${deviceType}`);
491490
pushToRootViewCssClasses(`${CLASS_PREFIX}${iosApp.orientation}`);
492491

493-
if (majorVersion >= 13) {
494-
pushToRootViewCssClasses(`${CLASS_PREFIX}${iosApp.systemAppearance}`);
495-
}
496-
497492
const rootViewCssClasses = getRootViewCssClasses();
498493
rootViewCssClasses.forEach(c => rootView.cssClasses.add(c));
499494
}
500495

496+
function setRootViewSystemAppearanceCssClass(rootView: View): void {
497+
if (majorVersion >= 13) {
498+
const systemAppearanceCssClass = `${CLASS_PREFIX}${iosApp.systemAppearance}`;
499+
pushToRootViewCssClasses(systemAppearanceCssClass);
500+
rootView.cssClasses.add(systemAppearanceCssClass);
501+
}
502+
}
503+
501504
export function orientation(): "portrait" | "landscape" | "unknown" {
502505
return iosApp.orientation;
503506
}

nativescript-core/css/system-classes.d.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,3 @@ export function pushToRootViewCssClasses(value: string): number;
2828
* @param value
2929
*/
3030
export function removeFromRootViewCssClasses(value: string): string;
31-
32-
/**
33-
* Resets CSS classes for root view.
34-
*/
35-
export function resetRootViewCssClasses(): string[];

nativescript-core/css/system-classes.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,3 @@ export function removeFromRootViewCssClasses(value: string): string {
3030

3131
return removedElement;
3232
}
33-
34-
export function resetRootViewCssClasses(): string[] {
35-
// Preserve the default `ns-root` CSS class
36-
return rootViewCssClasses.splice(1);
37-
}

0 commit comments

Comments
 (0)