diff --git a/tns-core-modules/application/application.ios.ts b/tns-core-modules/application/application.ios.ts index a196d24f7..31c5ad7d1 100644 --- a/tns-core-modules/application/application.ios.ts +++ b/tns-core-modules/application/application.ios.ts @@ -21,6 +21,7 @@ import { CLASS_PREFIX, getRootViewCssClasses, pushToRootViewCssClasses, + removeFromRootViewCssClasses, resetRootViewCssClasses } from "../css/system-classes"; import { ios as iosView, View } from "../ui/core/view"; @@ -31,6 +32,12 @@ import { ios } from "../utils/utils"; const IOS_PLATFORM = "ios"; +// TODO: +const UI_STYLE_CSS_CLASSES = [ + `${CLASS_PREFIX}light`, + `${CLASS_PREFIX}dark` +]; + const getVisibleViewController = ios.getVisibleViewController; // NOTE: UIResponder with implementation of window - related to https://github.com/NativeScript/ios-runtime/issues/430 @@ -288,6 +295,26 @@ class IOSApplication implements IOSApplicationDefinition { } setupRootViewCssClasses(controller, rootView); + + rootView.on(iosView.traitCollectionColorAppearanceChangedEvent, () => { + + const newUserInterfaceStyle = controller.traitCollection.userInterfaceStyle; + const newUserInterfaceStyleValue = getUserInterfaceStyleValue(newUserInterfaceStyle); + const newUserInterfaceStyleCssClass = `${CLASS_PREFIX}${newUserInterfaceStyleValue}`; + + if (!rootView.cssClasses.has(newUserInterfaceStyleCssClass)) { + const removeCssClass = (c: string) => { + removeFromRootViewCssClasses(c); + rootView.cssClasses.delete(c); + }; + + // TODO: + UI_STYLE_CSS_CLASSES.forEach(c => removeCssClass(c)); + pushToRootViewCssClasses(newUserInterfaceStyleCssClass); + rootView.cssClasses.add(newUserInterfaceStyleCssClass); + rootView._onCssStateChange(); + } + }); } } @@ -359,6 +386,7 @@ export function _start(entry?: string | NavigationEntry) { } setupRootViewCssClasses(controller, rootView); + // TODO: iosApp.notifyAppStarted(); } }