From aa34d4a0b41ebf25527bbc3cb5792175e77105b7 Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Wed, 4 Nov 2015 16:24:05 +0200 Subject: [PATCH] TextField, Label and Button CSS type selectors will affect dialogs as well --- apps/gallery-app/app.css | 9 ++++++ ui/dialogs/dialogs-common.ts | 61 ++++++++++++++++++++++++++++++++++- ui/dialogs/dialogs.android.ts | 35 ++++++++++++++++---- ui/dialogs/dialogs.ios.ts | 37 ++++++++++++++++++--- 4 files changed, 130 insertions(+), 12 deletions(-) diff --git a/apps/gallery-app/app.css b/apps/gallery-app/app.css index 99315f958..0dc6af8bc 100644 --- a/apps/gallery-app/app.css +++ b/apps/gallery-app/app.css @@ -11,3 +11,12 @@ ScrollView { font-size: 24; margin: 6 0; } +/* +ActionBar, TabView, ActivityIndicator, Label, Button, TextView, TextField, SearchBar, ListPicker, DatePicker, TimePicker { + color: mediumaquamarine; +} + +Switch, Progress, Slider, SegmentedBar { + color: mediumaquamarine; + background-color: aquamarine; +}*/ \ No newline at end of file diff --git a/ui/dialogs/dialogs-common.ts b/ui/dialogs/dialogs-common.ts index 6d347d972..dd175abdd 100644 --- a/ui/dialogs/dialogs-common.ts +++ b/ui/dialogs/dialogs-common.ts @@ -1,4 +1,11 @@ -export var STRING = "string", +import color = require("color"); +import frame = require("ui/frame"); +import page = require("ui/page"); +import button = require("ui/button"); +import textField = require("ui/text-field"); +import label = require("ui/label"); + +export var STRING = "string", PROMPT = "Prompt", CONFIRM = "Confirm", ALERT = "Alert", @@ -19,4 +26,56 @@ export module inputType { * Password input type. */ export var password: string = "password"; +} + +export function getCurrentPage(): page.Page { + var topMostFrame = frame.topmost(); + if (topMostFrame) { + return topMostFrame.currentPage; + } + + return undefined; +} + +function applySelectors(view) { + var currentPage = getCurrentPage(); + if (currentPage) { + var styleScope = currentPage._getStyleScope(); + if (styleScope) { + styleScope.applySelectors(view); + } + } +} + +var buttonColor: color.Color; +export function getButtonColor(): color.Color { + if (!buttonColor) { + var btn = new button.Button(); + applySelectors(btn); + buttonColor = btn.color; + } + + return buttonColor; +} + +var textFieldColor: color.Color; +export function getTextFieldColor(): color.Color { + if (!textFieldColor) { + var tf = new textField.TextField(); + applySelectors(tf); + textFieldColor = tf.color; + } + + return textFieldColor; +} + +var labelColor: color.Color; +export function getLabelColor(): color.Color { + if (!labelColor) { + var lbl = new label.Label(); + applySelectors(lbl); + labelColor = lbl.color; + } + + return labelColor; } \ No newline at end of file diff --git a/ui/dialogs/dialogs.android.ts b/ui/dialogs/dialogs.android.ts index 625e1639c..ef3dfcad4 100644 --- a/ui/dialogs/dialogs.android.ts +++ b/ui/dialogs/dialogs.android.ts @@ -16,6 +16,29 @@ function createAlertDialog(options?: dialogs.DialogOptions): android.app.AlertDi return alert; } +function showDialog(builder: android.app.AlertDialog.Builder) { + var dlg = builder.show(); + + var labelColor = dialogsCommon.getLabelColor(); + if (labelColor) { + var textViewId = dlg.getContext().getResources().getIdentifier("android:id/alertTitle", null, null); + if (textViewId) { + var tv = dlg.findViewById(textViewId); + if (tv) { + tv.setTextColor(labelColor.android); + } + } + + var messageTextViewId = dlg.getContext().getResources().getIdentifier("android:id/message", null, null); + if (messageTextViewId) { + var messageTextView = dlg.findViewById(messageTextViewId); + if (messageTextView) { + messageTextView.setTextColor(labelColor.android); + } + } + } +} + function addButtonsToAlertDialog(alert: android.app.AlertDialog.Builder, options: dialogs.ConfirmOptions, callback: Function): void { @@ -65,7 +88,7 @@ export function alert(arg: any): Promise { } })); - alert.show(); + showDialog(alert); } catch (ex) { reject(ex); @@ -81,7 +104,7 @@ export function confirm(arg: any): Promise { addButtonsToAlertDialog(alert, options, function (result) { resolve(result); }); - alert.show(); + showDialog(alert); } catch (ex) { reject(ex); @@ -132,7 +155,7 @@ export function prompt(arg: any): Promise { addButtonsToAlertDialog(alert, options, function (r) { resolve({ result: r, text: getText() }); }); - alert.show(); + showDialog(alert); } catch (ex) { reject(ex); @@ -196,7 +219,7 @@ export function login(arg: any): Promise { }); }); - alert.show(); + showDialog(alert); } catch (ex) { reject(ex); @@ -239,7 +262,7 @@ export function action(arg: any): Promise { var alert = new android.app.AlertDialog.Builder(activity); var message = options && types.isString(options.message) ? options.message : ""; var title = options && types.isString(options.title) ? options.title : ""; - + if (title) { alert.setTitle(title); if (!options.actions) { @@ -266,7 +289,7 @@ export function action(arg: any): Promise { } })); } - alert.show(); + showDialog(alert); } catch (ex) { reject(ex); diff --git a/ui/dialogs/dialogs.ios.ts b/ui/dialogs/dialogs.ios.ts index 2c452c572..74ebfe7ad 100644 --- a/ui/dialogs/dialogs.ios.ts +++ b/ui/dialogs/dialogs.ios.ts @@ -6,7 +6,6 @@ import dialogs = require("ui/dialogs"); import dialogsCommon = require("./dialogs-common"); import types = require("utils/types"); import utils = require("utils/utils"); -import frame = require("ui/frame"); global.moduleMerge(dialogsCommon, exports); @@ -51,7 +50,7 @@ class UIActionSheetDelegateImpl extends NSObject implements UIActionSheetDelegat function createUIAlertView(options: dialogs.DialogOptions): UIAlertView { var alert = new UIAlertView(); alert.title = options && options.title ? options.title : ""; - alert.message = options && options.message ? options.message : "";; + alert.message = options && options.message ? options.message : ""; return alert; } @@ -263,6 +262,11 @@ export function prompt(arg: any): Promise { alertController.addTextFieldWithConfigurationHandler((arg: UITextField) => { arg.text = types.isString(options.defaultText) ? options.defaultText : ""; arg.secureTextEntry = options && options.inputType === dialogs.inputType.password; + + var color = dialogsCommon.getTextFieldColor(); + if (color) { + arg.textColor = arg.tintColor = color.ios; + } }); textField = alertController.textFields.firstObject; @@ -340,12 +344,22 @@ export function login(arg: any): Promise { alertController.addTextFieldWithConfigurationHandler((arg: UITextField) => { arg.placeholder = "Login"; arg.text = types.isString(options.userName) ? options.userName : ""; + + var color = dialogsCommon.getTextFieldColor(); + if (color) { + arg.textColor = arg.tintColor = color.ios; + } }); alertController.addTextFieldWithConfigurationHandler((arg: UITextField) => { arg.placeholder = "Password"; arg.secureTextEntry = true; arg.text = types.isString(options.password) ? options.password : ""; + + var color = dialogsCommon.getTextFieldColor(); + if (color) { + arg.textColor = arg.tintColor = color.ios; + } }); userNameTextField = alertController.textFields.firstObject; @@ -373,9 +387,9 @@ export function login(arg: any): Promise { } function showUIAlertController(alertController: UIAlertController) { - var topMostFrame = frame.topmost(); - if (topMostFrame) { - var viewController: UIViewController = topMostFrame.currentPage && topMostFrame.currentPage.ios; + var currentPage = dialogsCommon.getCurrentPage(); + if (currentPage) { + var viewController: UIViewController = currentPage.ios; if (viewController) { if (alertController.popoverPresentationController) { alertController.popoverPresentationController.sourceView = viewController.view; @@ -383,6 +397,19 @@ function showUIAlertController(alertController: UIAlertController) { alertController.popoverPresentationController.permittedArrowDirections = 0; } + var color = dialogsCommon.getButtonColor(); + if (color) { + alertController.view.tintColor = color.ios; + } + + var lblColor = dialogsCommon.getLabelColor(); + if (lblColor) { + var title = NSAttributedString.alloc().initWithStringAttributes(alertController.title, { [NSForegroundColorAttributeName]: lblColor.ios }); + alertController.setValueForKey(title, "attributedTitle"); + var message = NSAttributedString.alloc().initWithStringAttributes(alertController.message, { [NSForegroundColorAttributeName]: lblColor.ios }); + alertController.setValueForKey(message, "attributedMessage"); + } + viewController.presentModalViewControllerAnimated(alertController, true); } }