From cb1f7cc18249554d9c8be51924bcd20201687baf Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Tue, 17 Sep 2019 18:26:45 +0300 Subject: [PATCH] refactor(dark-mode): arrow functions to properties --- tns-core-modules/application/application.ios.ts | 5 ++--- .../activity-indicator/activity-indicator.ios.ts | 4 ++-- tns-core-modules/ui/page/page.ios.ts | 5 ++--- tns-core-modules/ui/tabs/tabs.ios.ts | 15 +++++++-------- tns-core-modules/ui/text-view/text-view.ios.ts | 10 +++++----- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/tns-core-modules/application/application.ios.ts b/tns-core-modules/application/application.ios.ts index f048fb975..33220468a 100644 --- a/tns-core-modules/application/application.ios.ts +++ b/tns-core-modules/application/application.ios.ts @@ -82,14 +82,13 @@ class CADisplayLinkTarget extends NSObject { } class IOSApplication implements IOSApplicationDefinition { + private _backgroundColor = majorVersion <= 12 ? UIColor.whiteColor : UIColor.systemBackgroundColor; private _delegate: typeof UIApplicationDelegate; private _window: UIWindow; private _observers: Array; 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)); @@ -162,7 +161,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 = this.getBackgroundColor(); + this._window.backgroundColor = this._backgroundColor; this.notifyAppStarted(notification); } 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 717c3587a..9ce1dfb51 100644 --- a/tns-core-modules/ui/activity-indicator/activity-indicator.ios.ts +++ b/tns-core-modules/ui/activity-indicator/activity-indicator.ios.ts @@ -9,10 +9,10 @@ const majorVersion = ios.MajorVersion; export class ActivityIndicator extends ActivityIndicatorBase { nativeViewProtected: UIActivityIndicatorView; - private getActivityIndicatorViewStyle = () => majorVersion <= 12 ? UIActivityIndicatorViewStyle.Gray : UIActivityIndicatorViewStyle.Medium; + private _activityIndicatorViewStyle = majorVersion <= 12 ? UIActivityIndicatorViewStyle.Gray : UIActivityIndicatorViewStyle.Medium; createNativeView() { - const viewStyle = this.getActivityIndicatorViewStyle(); + const viewStyle = this._activityIndicatorViewStyle; const view = UIActivityIndicatorView.alloc().initWithActivityIndicatorStyle(viewStyle); view.hidesWhenStopped = true; diff --git a/tns-core-modules/ui/page/page.ios.ts b/tns-core-modules/ui/page/page.ios.ts index f69028a23..d021b75a3 100644 --- a/tns-core-modules/ui/page/page.ios.ts +++ b/tns-core-modules/ui/page/page.ios.ts @@ -286,8 +286,7 @@ export class Page extends PageBase { nativeViewProtected: UIView; viewController: UIViewControllerImpl; - private getBackgroundColor = () => majorVersion <= 12 ? UIColor.whiteColor : UIColor.systemBackgroundColor; - + private _backgroundColor = majorVersion <= 12 ? UIColor.whiteColor : UIColor.systemBackgroundColor; private _ios: UIViewControllerImpl; public _presentedViewController: UIViewController; // used when our page present native viewController without going through our abstraction. @@ -297,7 +296,7 @@ export class Page extends PageBase { this.viewController = this._ios = controller; // Make transitions look good - controller.view.backgroundColor = this.getBackgroundColor(); + controller.view.backgroundColor = this._backgroundColor; } createNativeView() { diff --git a/tns-core-modules/ui/tabs/tabs.ios.ts b/tns-core-modules/ui/tabs/tabs.ios.ts index 73f9efb7f..a0158b1cf 100644 --- a/tns-core-modules/ui/tabs/tabs.ios.ts +++ b/tns-core-modules/ui/tabs/tabs.ios.ts @@ -24,10 +24,6 @@ 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]; @@ -74,6 +70,9 @@ class UIPageViewControllerImpl extends UIPageViewController { scrollView: UIScrollView; tabBarDelegate: MDCTabBarDelegateImpl; + private _backgroundColor = majorVersion <= 12 ? UIColor.whiteColor : UIColor.systemBackgroundColor; + private _blueColor = majorVersion <= 12 ? UIColor.blueColor : UIColor.systemBlueColor; + private _labelColor = majorVersion <= 12 ? UIColor.blackColor : UIColor.labelColor; private _owner: WeakRef; public static initWithOwner(owner: WeakRef): UIPageViewControllerImpl { @@ -94,10 +93,10 @@ class UIPageViewControllerImpl extends UIPageViewController { } tabBar.delegate = this.tabBarDelegate = MDCTabBarDelegateImpl.initWithOwner(new WeakRef(owner)); - tabBar.tintColor = getBlueColor(); - tabBar.barTintColor = getBackgroundColor(); - tabBar.setTitleColorForState(getLabelColor(), MDCTabBarItemState.Normal); - tabBar.setTitleColorForState(getLabelColor(), MDCTabBarItemState.Selected); + tabBar.tintColor = this._blueColor; + tabBar.barTintColor = this._backgroundColor; + tabBar.setTitleColorForState(this._labelColor, MDCTabBarItemState.Normal); + tabBar.setTitleColorForState(this._labelColor, MDCTabBarItemState.Selected); if (majorVersion >= 13) { tabBar.inkColor = UIColor.clearColor; diff --git a/tns-core-modules/ui/text-view/text-view.ios.ts b/tns-core-modules/ui/text-view/text-view.ios.ts index 6a357e115..a1411cffd 100644 --- a/tns-core-modules/ui/text-view/text-view.ios.ts +++ b/tns-core-modules/ui/text-view/text-view.ios.ts @@ -116,8 +116,8 @@ export class TextView extends EditableTextBase implements TextViewDefinition { private _isShowingHint: boolean; public _isEditing: boolean; - private getHintColor = () => majorVersion <= 12 ? UIColor.blackColor.colorWithAlphaComponent(0.22) : UIColor.placeholderTextColor; - private getTextColor = () => majorVersion <= 12 ? null : UIColor.labelColor; + private _hintColor = majorVersion <= 12 ? UIColor.blackColor.colorWithAlphaComponent(0.22) : UIColor.placeholderTextColor; + private _textColor = majorVersion <= 12 ? null : UIColor.labelColor; createNativeView() { const textView = NoScrollAnimationUITextView.new(); @@ -179,7 +179,7 @@ export class TextView extends EditableTextBase implements TextViewDefinition { // Use semi-transparent version of color for back-compatibility this.nativeTextViewProtected.textColor = color.ios.colorWithAlphaComponent(0.22); } else { - this.nativeTextViewProtected.textColor = this.getHintColor(); + this.nativeTextViewProtected.textColor = this._hintColor; } } else { const color = this.style.color; @@ -188,8 +188,8 @@ export class TextView extends EditableTextBase implements TextViewDefinition { this.nativeTextViewProtected.textColor = color.ios; this.nativeTextViewProtected.tintColor = color.ios; } else { - this.nativeTextViewProtected.textColor = this.getTextColor(); - this.nativeTextViewProtected.tintColor = this.getTextColor(); + this.nativeTextViewProtected.textColor = this._textColor; + this.nativeTextViewProtected.tintColor = this._textColor; } } }