mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
TextField, Label and Button CSS type selectors will affect dialogs as well
This commit is contained in:
@ -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;
|
||||
}*/
|
@ -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;
|
||||
}
|
@ -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 = <android.widget.TextView>dlg.findViewById(textViewId);
|
||||
if (tv) {
|
||||
tv.setTextColor(labelColor.android);
|
||||
}
|
||||
}
|
||||
|
||||
var messageTextViewId = dlg.getContext().getResources().getIdentifier("android:id/message", null, null);
|
||||
if (messageTextViewId) {
|
||||
var messageTextView = <android.widget.TextView>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<void> {
|
||||
}
|
||||
}));
|
||||
|
||||
alert.show();
|
||||
showDialog(alert);
|
||||
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
@ -81,7 +104,7 @@ export function confirm(arg: any): Promise<boolean> {
|
||||
|
||||
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<dialogs.PromptResult> {
|
||||
|
||||
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<dialogs.LoginResult> {
|
||||
});
|
||||
});
|
||||
|
||||
alert.show();
|
||||
showDialog(alert);
|
||||
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
@ -239,7 +262,7 @@ export function action(arg: any): Promise<string> {
|
||||
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<string> {
|
||||
}
|
||||
}));
|
||||
}
|
||||
alert.show();
|
||||
showDialog(alert);
|
||||
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
|
@ -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<dialogs.PromptResult> {
|
||||
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<dialogs.LoginResult> {
|
||||
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<dialogs.LoginResult> {
|
||||
}
|
||||
|
||||
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, <any>{ [NSForegroundColorAttributeName]: lblColor.ios });
|
||||
alertController.setValueForKey(title, "attributedTitle");
|
||||
var message = NSAttributedString.alloc().initWithStringAttributes(alertController.message, <any>{ [NSForegroundColorAttributeName]: lblColor.ios });
|
||||
alertController.setValueForKey(message, "attributedMessage");
|
||||
}
|
||||
|
||||
viewController.presentModalViewControllerAnimated(alertController, true);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user