refactor(dark-mode): remove compatibility color module

This commit is contained in:
Vasil Chimev
2019-09-15 15:55:50 +03:00
parent 3de233887a
commit dfda58111e
6 changed files with 23 additions and 26 deletions

View File

@ -20,7 +20,6 @@ import { createViewFromEntry } from "../ui/builder";
import { CLASS_PREFIX, getRootViewCssClasses, pushToRootViewCssClasses } from "../css/system-classes"; import { CLASS_PREFIX, getRootViewCssClasses, pushToRootViewCssClasses } from "../css/system-classes";
import { ios as iosView, View } from "../ui/core/view"; import { ios as iosView, View } from "../ui/core/view";
import { Frame, NavigationEntry } from "../ui/frame"; import { Frame, NavigationEntry } from "../ui/frame";
import { backgroundColor } from "../color/compatibility-colors.ios";
import { device } from "../platform/platform"; import { device } from "../platform/platform";
import { profile } from "../profiling"; import { profile } from "../profiling";
import { ios } from "../utils/utils"; import { ios } from "../utils/utils";
@ -28,6 +27,7 @@ import { ios } from "../utils/utils";
const IOS_PLATFORM = "ios"; const IOS_PLATFORM = "ios";
const getVisibleViewController = ios.getVisibleViewController; const getVisibleViewController = ios.getVisibleViewController;
const majorVersion = ios.MajorVersion;
// 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
// TODO: Refactor the UIResponder to use Typescript extends when this issue is resolved: // 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 _orientation: "portrait" | "landscape" | "unknown";
private _rootView: View; private _rootView: View;
private getBackgroundColor = () => majorVersion <= 12 ? UIColor.whiteColor : UIColor.systemBackgroundColor;
constructor() { constructor() {
this._observers = new Array<NotificationObserver>(); this._observers = new Array<NotificationObserver>();
this.addNotificationObserver(UIApplicationDidFinishLaunchingNotification, this.didFinishLaunchingWithOptions.bind(this)); this.addNotificationObserver(UIApplicationDidFinishLaunchingNotification, this.didFinishLaunchingWithOptions.bind(this));
@ -160,7 +162,7 @@ class IOSApplication implements IOSApplicationDefinition {
this._window = UIWindow.alloc().initWithFrame(UIScreen.mainScreen.bounds); this._window = UIWindow.alloc().initWithFrame(UIScreen.mainScreen.bounds);
// TODO: Expose Window module so that it can we styled from XML & CSS // 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); this.notifyAppStarted(notification);
} }

View File

@ -1,3 +0,0 @@
/**
* @module "color/compatibility-colors"
*/ /** */

View File

@ -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;

View File

@ -1,13 +1,19 @@
import { ActivityIndicatorBase, busyProperty, colorProperty, Color } from "./activity-indicator-common"; import { ActivityIndicatorBase, busyProperty, colorProperty, Color } from "./activity-indicator-common";
import { activityIndicatorViewStyle } from "../../color/compatibility-colors.ios";
export * from "./activity-indicator-common"; export * from "./activity-indicator-common";
import { ios } from "../../utils/utils";
const majorVersion = ios.MajorVersion;
export class ActivityIndicator extends ActivityIndicatorBase { export class ActivityIndicator extends ActivityIndicatorBase {
nativeViewProtected: UIActivityIndicatorView; nativeViewProtected: UIActivityIndicatorView;
private getActivityIndicatorViewStyle = () => majorVersion <= 12 ? UIActivityIndicatorViewStyle.Gray : UIActivityIndicatorViewStyle.Medium;
createNativeView() { createNativeView() {
const view = UIActivityIndicatorView.alloc().initWithActivityIndicatorStyle(activityIndicatorViewStyle()); const viewStyle = this.getActivityIndicatorViewStyle();
const view = UIActivityIndicatorView.alloc().initWithActivityIndicatorStyle(viewStyle);
view.hidesWhenStopped = true; view.hidesWhenStopped = true;
return view; return view;

View File

@ -8,7 +8,6 @@ import {
PageBase, View, layout, actionBarHiddenProperty, statusBarStyleProperty, Color PageBase, View, layout, actionBarHiddenProperty, statusBarStyleProperty, Color
} from "./page-common"; } from "./page-common";
import { backgroundColor } from "../../color/compatibility-colors.ios";
import { profile } from "../../profiling"; import { profile } from "../../profiling";
import { ios as iosUtils } from "../../utils/utils"; import { ios as iosUtils } from "../../utils/utils";
@ -287,6 +286,8 @@ export class Page extends PageBase {
nativeViewProtected: UIView; nativeViewProtected: UIView;
viewController: UIViewControllerImpl; viewController: UIViewControllerImpl;
private getBackgroundColor = () => majorVersion <= 12 ? UIColor.whiteColor : UIColor.systemBackgroundColor;
private _ios: UIViewControllerImpl; private _ios: UIViewControllerImpl;
public _presentedViewController: UIViewController; // used when our page present native viewController without going through our abstraction. 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; this.viewController = this._ios = controller;
// Make transitions look good // Make transitions look good
controller.view.backgroundColor = backgroundColor(); controller.view.backgroundColor = this.getBackgroundColor();
} }
createNativeView() { createNativeView() {

View File

@ -6,7 +6,6 @@ import { TextTransform } from "../text-base";
// Requires // Requires
import { Color } from "../../color"; import { Color } from "../../color";
import { backgroundColor, blueColor, labelColor } from "../../color/compatibility-colors.ios";
import { fromFileOrResource, fromFontIconCode, ImageSource } from "../../image-source"; import { fromFileOrResource, fromFontIconCode, ImageSource } from "../../image-source";
import { ios as iosUtils, isFontIconURI, layout } from "../../utils/utils"; import { ios as iosUtils, isFontIconURI, layout } from "../../utils/utils";
import { ios as iosView, View } from "../core/view"; import { ios as iosView, View } from "../core/view";
@ -25,6 +24,10 @@ export * from "./tabs-common";
const majorVersion = iosUtils.MajorVersion; const majorVersion = iosUtils.MajorVersion;
// const isPhone = device.deviceType === "Phone"; // 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 { class MDCTabBarDelegateImpl extends NSObject implements MDCTabBarDelegate {
public static ObjCProtocols = [MDCTabBarDelegate]; public static ObjCProtocols = [MDCTabBarDelegate];
@ -91,10 +94,10 @@ class UIPageViewControllerImpl extends UIPageViewController {
} }
tabBar.delegate = this.tabBarDelegate = MDCTabBarDelegateImpl.initWithOwner(new WeakRef(owner)); tabBar.delegate = this.tabBarDelegate = MDCTabBarDelegateImpl.initWithOwner(new WeakRef(owner));
tabBar.tintColor = blueColor(); tabBar.tintColor = getBlueColor();
tabBar.barTintColor = backgroundColor(); tabBar.barTintColor = getBackgroundColor();
tabBar.setTitleColorForState(labelColor(), MDCTabBarItemState.Normal); tabBar.setTitleColorForState(getLabelColor(), MDCTabBarItemState.Normal);
tabBar.setTitleColorForState(labelColor(), MDCTabBarItemState.Selected); tabBar.setTitleColorForState(getLabelColor(), MDCTabBarItemState.Selected);
if (majorVersion >= 13) { if (majorVersion >= 13) {
tabBar.inkColor = UIColor.clearColor; tabBar.inkColor = UIColor.clearColor;