From d36205d13f1608dc00be7d1d830fcedd3f4fa9c5 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Mon, 9 Sep 2019 20:52:47 +0300 Subject: [PATCH] fix(dark-mode): window and page background color --- tns-core-modules/application/application.ios.ts | 17 +++++++++++++---- tns-core-modules/ui/page/page.ios.ts | 15 ++++++++++++--- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/tns-core-modules/application/application.ios.ts b/tns-core-modules/application/application.ios.ts index 49e9b80cb..8886119a4 100644 --- a/tns-core-modules/application/application.ios.ts +++ b/tns-core-modules/application/application.ios.ts @@ -32,6 +32,7 @@ const ROOT_VIEW_CSS_CLASSES = [ `${CSS_CLASS_PREFIX}${IOS_PLATFORM}` ]; const getVisibleViewController = ios.getVisibleViewController; +const majorVersion = ios.MajorVersion; // NOTE: UIResponder with implementation of window - related to https://github.com/NativeScript/ios-runtime/issues/430 // TODO: Refactor the UIResponder to use Typescript extends when this issue is resolved: @@ -44,8 +45,8 @@ const Responder = (UIResponder).extend({ // NOOP } }, { - protocols: [UIApplicationDelegate] - } + protocols: [UIApplicationDelegate] +} ); class NotificationObserver extends NSObject { @@ -163,11 +164,19 @@ class IOSApplication implements IOSApplicationDefinition { } this._window = UIWindow.alloc().initWithFrame(UIScreen.mainScreen.bounds); + + // TODO: add CompatibilityColor.backgroundColor; + let backgroundColor; + if (majorVersion <= 12) { + backgroundColor = UIColor.whiteColor; + } else { + backgroundColor = UIColor.systemBackgroundColor; + } + // TODO: Expose Window module so that it can we styled from XML & CSS - this._window.backgroundColor = UIColor.whiteColor; + this._window.backgroundColor = backgroundColor; this.notifyAppStarted(notification); - } public notifyAppStarted(notification?: NSNotification) { diff --git a/tns-core-modules/ui/page/page.ios.ts b/tns-core-modules/ui/page/page.ios.ts index 093cf0970..12d360ee8 100644 --- a/tns-core-modules/ui/page/page.ios.ts +++ b/tns-core-modules/ui/page/page.ios.ts @@ -148,7 +148,7 @@ class UIViewControllerImpl extends UIViewController { const isReplace = navigationContext.navigationType === NavigationType.replace; frame.setCurrent(newEntry, navigationContext.navigationType); - + if (isReplace) { let controller = newEntry.resolvedPage.ios; if (controller) { @@ -282,7 +282,6 @@ class UIViewControllerImpl extends UIViewController { } } -const whiteColor = new Color("white").ios; export class Page extends PageBase { nativeViewProtected: UIView; viewController: UIViewControllerImpl; @@ -294,7 +293,17 @@ export class Page extends PageBase { super(); const controller = UIViewControllerImpl.initWithOwner(new WeakRef(this)); this.viewController = this._ios = controller; - controller.view.backgroundColor = whiteColor; + + // Make transitions look good + let backgroundColor; + if (majorVersion <= 12) { + backgroundColor = UIColor.whiteColor; + } else { + backgroundColor = UIColor.systemBackgroundColor; + } + + // TODO: add CompatibilityColor.backgroundColor; + controller.view.backgroundColor = backgroundColor; } createNativeView() {