From dfda58111eb5247bbb310b9961d77aa32caa7e18 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Sun, 15 Sep 2019 15:55:50 +0300 Subject: [PATCH] refactor(dark-mode): remove compatibility color module --- tns-core-modules/application/application.ios.ts | 6 ++++-- tns-core-modules/color/compatibility-colors.d.ts | 3 --- tns-core-modules/color/compatibility-colors.ios.ts | 12 ------------ .../ui/activity-indicator/activity-indicator.ios.ts | 10 ++++++++-- tns-core-modules/ui/page/page.ios.ts | 5 +++-- tns-core-modules/ui/tabs/tabs.ios.ts | 13 ++++++++----- 6 files changed, 23 insertions(+), 26 deletions(-) delete mode 100644 tns-core-modules/color/compatibility-colors.d.ts delete mode 100644 tns-core-modules/color/compatibility-colors.ios.ts diff --git a/tns-core-modules/application/application.ios.ts b/tns-core-modules/application/application.ios.ts index 4215a864d..f048fb975 100644 --- a/tns-core-modules/application/application.ios.ts +++ b/tns-core-modules/application/application.ios.ts @@ -20,7 +20,6 @@ import { createViewFromEntry } from "../ui/builder"; import { CLASS_PREFIX, getRootViewCssClasses, pushToRootViewCssClasses } from "../css/system-classes"; import { ios as iosView, View } from "../ui/core/view"; import { Frame, NavigationEntry } from "../ui/frame"; -import { backgroundColor } from "../color/compatibility-colors.ios"; import { device } from "../platform/platform"; import { profile } from "../profiling"; import { ios } from "../utils/utils"; @@ -28,6 +27,7 @@ import { ios } from "../utils/utils"; const IOS_PLATFORM = "ios"; 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: @@ -88,6 +88,8 @@ class IOSApplication implements IOSApplicationDefinition { private _orientation: "portrait" | "landscape" | "unknown"; private _rootView: View; + private getBackgroundColor = () => majorVersion <= 12 ? UIColor.whiteColor : UIColor.systemBackgroundColor; + constructor() { this._observers = new Array(); this.addNotificationObserver(UIApplicationDidFinishLaunchingNotification, this.didFinishLaunchingWithOptions.bind(this)); @@ -160,7 +162,7 @@ class IOSApplication implements IOSApplicationDefinition { this._window = UIWindow.alloc().initWithFrame(UIScreen.mainScreen.bounds); // TODO: Expose Window module so that it can we styled from XML & CSS - this._window.backgroundColor = backgroundColor(); + this._window.backgroundColor = this.getBackgroundColor(); this.notifyAppStarted(notification); } diff --git a/tns-core-modules/color/compatibility-colors.d.ts b/tns-core-modules/color/compatibility-colors.d.ts deleted file mode 100644 index 83bb5ebe4..000000000 --- a/tns-core-modules/color/compatibility-colors.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/** - * @module "color/compatibility-colors" - */ /** */ diff --git a/tns-core-modules/color/compatibility-colors.ios.ts b/tns-core-modules/color/compatibility-colors.ios.ts deleted file mode 100644 index 579f7d1c1..000000000 --- a/tns-core-modules/color/compatibility-colors.ios.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { ios } from "../utils/utils"; - -const majorVersion = ios.MajorVersion; - -export const activityIndicatorViewStyle = () => majorVersion <= 12 ? UIActivityIndicatorViewStyle.Gray : UIActivityIndicatorViewStyle.Medium; - -// UI Element Colors -export const backgroundColor = () => majorVersion <= 12 ? UIColor.whiteColor : UIColor.systemBackgroundColor; -export const labelColor = () => majorVersion <= 12 ? UIColor.blackColor : UIColor.labelColor; - -// Standard Colors -export const blueColor = () => majorVersion <= 12 ? UIColor.blueColor : UIColor.systemBlueColor; diff --git a/tns-core-modules/ui/activity-indicator/activity-indicator.ios.ts b/tns-core-modules/ui/activity-indicator/activity-indicator.ios.ts index 84fad6f2c..717c3587a 100644 --- a/tns-core-modules/ui/activity-indicator/activity-indicator.ios.ts +++ b/tns-core-modules/ui/activity-indicator/activity-indicator.ios.ts @@ -1,13 +1,19 @@ import { ActivityIndicatorBase, busyProperty, colorProperty, Color } from "./activity-indicator-common"; -import { activityIndicatorViewStyle } from "../../color/compatibility-colors.ios"; export * from "./activity-indicator-common"; +import { ios } from "../../utils/utils"; + +const majorVersion = ios.MajorVersion; + export class ActivityIndicator extends ActivityIndicatorBase { nativeViewProtected: UIActivityIndicatorView; + private getActivityIndicatorViewStyle = () => majorVersion <= 12 ? UIActivityIndicatorViewStyle.Gray : UIActivityIndicatorViewStyle.Medium; + createNativeView() { - const view = UIActivityIndicatorView.alloc().initWithActivityIndicatorStyle(activityIndicatorViewStyle()); + const viewStyle = this.getActivityIndicatorViewStyle(); + const view = UIActivityIndicatorView.alloc().initWithActivityIndicatorStyle(viewStyle); view.hidesWhenStopped = true; return view; diff --git a/tns-core-modules/ui/page/page.ios.ts b/tns-core-modules/ui/page/page.ios.ts index 912f2fa2e..f69028a23 100644 --- a/tns-core-modules/ui/page/page.ios.ts +++ b/tns-core-modules/ui/page/page.ios.ts @@ -8,7 +8,6 @@ import { PageBase, View, layout, actionBarHiddenProperty, statusBarStyleProperty, Color } from "./page-common"; -import { backgroundColor } from "../../color/compatibility-colors.ios"; import { profile } from "../../profiling"; import { ios as iosUtils } from "../../utils/utils"; @@ -287,6 +286,8 @@ export class Page extends PageBase { nativeViewProtected: UIView; viewController: UIViewControllerImpl; + private getBackgroundColor = () => majorVersion <= 12 ? UIColor.whiteColor : UIColor.systemBackgroundColor; + private _ios: UIViewControllerImpl; public _presentedViewController: UIViewController; // used when our page present native viewController without going through our abstraction. @@ -296,7 +297,7 @@ export class Page extends PageBase { this.viewController = this._ios = controller; // Make transitions look good - controller.view.backgroundColor = backgroundColor(); + controller.view.backgroundColor = this.getBackgroundColor(); } createNativeView() { diff --git a/tns-core-modules/ui/tabs/tabs.ios.ts b/tns-core-modules/ui/tabs/tabs.ios.ts index 78756b2de..73f9efb7f 100644 --- a/tns-core-modules/ui/tabs/tabs.ios.ts +++ b/tns-core-modules/ui/tabs/tabs.ios.ts @@ -6,7 +6,6 @@ import { TextTransform } from "../text-base"; // Requires import { Color } from "../../color"; -import { backgroundColor, blueColor, labelColor } from "../../color/compatibility-colors.ios"; import { fromFileOrResource, fromFontIconCode, ImageSource } from "../../image-source"; import { ios as iosUtils, isFontIconURI, layout } from "../../utils/utils"; import { ios as iosView, View } from "../core/view"; @@ -25,6 +24,10 @@ export * from "./tabs-common"; const majorVersion = iosUtils.MajorVersion; // const isPhone = device.deviceType === "Phone"; +const getBackgroundColor = () => majorVersion <= 12 ? UIColor.whiteColor : UIColor.systemBackgroundColor; +const getBlueColor = () => majorVersion <= 12 ? UIColor.blueColor : UIColor.systemBlueColor; +const getLabelColor = () => majorVersion <= 12 ? UIColor.blackColor : UIColor.labelColor; + class MDCTabBarDelegateImpl extends NSObject implements MDCTabBarDelegate { public static ObjCProtocols = [MDCTabBarDelegate]; @@ -91,10 +94,10 @@ class UIPageViewControllerImpl extends UIPageViewController { } tabBar.delegate = this.tabBarDelegate = MDCTabBarDelegateImpl.initWithOwner(new WeakRef(owner)); - tabBar.tintColor = blueColor(); - tabBar.barTintColor = backgroundColor(); - tabBar.setTitleColorForState(labelColor(), MDCTabBarItemState.Normal); - tabBar.setTitleColorForState(labelColor(), MDCTabBarItemState.Selected); + tabBar.tintColor = getBlueColor(); + tabBar.barTintColor = getBackgroundColor(); + tabBar.setTitleColorForState(getLabelColor(), MDCTabBarItemState.Normal); + tabBar.setTitleColorForState(getLabelColor(), MDCTabBarItemState.Selected); if (majorVersion >= 13) { tabBar.inkColor = UIColor.clearColor;