feat(dark-mode): respect traitCollectionColorAppearanceChanged event

This commit is contained in:
Vasil Chimev
2019-09-30 17:46:13 +03:00
parent f98b6cbab6
commit feebb048bb

View File

@@ -21,6 +21,7 @@ import {
CLASS_PREFIX, CLASS_PREFIX,
getRootViewCssClasses, getRootViewCssClasses,
pushToRootViewCssClasses, pushToRootViewCssClasses,
removeFromRootViewCssClasses,
resetRootViewCssClasses resetRootViewCssClasses
} from "../css/system-classes"; } from "../css/system-classes";
import { ios as iosView, View } from "../ui/core/view"; import { ios as iosView, View } from "../ui/core/view";
@@ -31,6 +32,12 @@ import { ios } from "../utils/utils";
const IOS_PLATFORM = "ios"; const IOS_PLATFORM = "ios";
// TODO:
const UI_STYLE_CSS_CLASSES = [
`${CLASS_PREFIX}light`,
`${CLASS_PREFIX}dark`
];
const getVisibleViewController = ios.getVisibleViewController; const getVisibleViewController = ios.getVisibleViewController;
// NOTE: UIResponder with implementation of window - related to https://github.com/NativeScript/ios-runtime/issues/430 // 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); 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); setupRootViewCssClasses(controller, rootView);
// TODO:
iosApp.notifyAppStarted(); iosApp.notifyAppStarted();
} }
} }