| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - // Deifinitions. | ||
| 1 | + // Types. | ||
| 2 | 2 | import { View } from "../core/view"; | |
| 3 | 3 | import { Color } from "../../color"; | |
| 4 | 4 | import { Page } from "../page"; | |
@@ -42,77 +42,68 @@ export function getCurrentPage(): Page { | |||
| 42 | 42 | if (topmostFrame) { | |
| 43 | 43 | return topmostFrame.currentPage; | |
| 44 | 44 | } | |
| 45 | - | ||
| 45 | + | ||
| 46 | 46 | return undefined; | |
| 47 | 47 | } | |
| 48 | 48 | ||
| 49 | - function applySelectors(view: View) { | ||
| 49 | + function applySelectors<T extends View>(view: T, callback: (view: T) => void) { | ||
| 50 | 50 | let currentPage = getCurrentPage(); | |
| 51 | 51 | if (currentPage) { | |
| 52 | 52 | let styleScope = currentPage._styleScope; | |
| 53 | 53 | if (styleScope) { | |
| 54 | - styleScope.matchSelectors(view); | ||
| 54 | + view._inheritStyleScope(styleScope); | ||
| 55 | + view.onLoaded(); | ||
| 56 | + callback(view); | ||
| 57 | + view.onUnloaded(); | ||
| 55 | 58 | } | |
| 56 | 59 | } | |
| 57 | 60 | } | |
| 58 | 61 | ||
| 59 | - let buttonColor: Color; | ||
| 60 | - let buttonBackgroundColor: Color; | ||
| 61 | - | ||
| 62 | - function getButtonColors(): void { | ||
| 63 | - const Button = require("ui/button").Button; | ||
| 64 | - const btn = new Button(); | ||
| 65 | - applySelectors(btn); | ||
| 66 | - buttonColor = btn.color; | ||
| 67 | - buttonBackgroundColor = btn.backgroundColor; | ||
| 68 | - btn.onUnloaded(); | ||
| 69 | - } | ||
| 62 | + let button: View; | ||
| 63 | + let label: View; | ||
| 64 | + let textField: View; | ||
| 70 | 65 | ||
| 71 | - // NOTE: This will fail if app.css is changed. | ||
| 72 | - export function getButtonColor(): Color { | ||
| 73 | - if (!buttonColor) { | ||
| 74 | - getButtonColors(); | ||
| 66 | + export function getButtonColors(): { color: Color, backgroundColor: Color } { | ||
| 67 | + if (!button) { | ||
| 68 | + const Button = require("ui/button").Button; | ||
| 69 | + button = new Button; | ||
| 75 | 70 | } | |
| 76 | 71 | ||
| 77 | - return buttonColor; | ||
| 72 | + let buttonColor: Color; | ||
| 73 | + let buttonBackgroundColor: Color; | ||
| 74 | + applySelectors(button, (btn) => { | ||
| 75 | + buttonColor = btn.color; | ||
| 76 | + buttonBackgroundColor = <Color>btn.backgroundColor; | ||
| 77 | + }); | ||
| 78 | + return { color: buttonColor, backgroundColor: buttonBackgroundColor }; | ||
| 78 | 79 | } | |
| 79 | 80 | ||
| 80 | - // NOTE: This will fail if app.css is changed. | ||
| 81 | - export function getButtonBackgroundColor(): Color { | ||
| 82 | - if (!buttonBackgroundColor) { | ||
| 83 | - getButtonColors(); | ||
| 81 | + export function getLabelColor(): Color { | ||
| 82 | + if (!label) { | ||
| 83 | + const Label = require("ui/label").Label; | ||
| 84 | + label = new Label; | ||
| 84 | 85 | } | |
| 85 | 86 | ||
| 86 | - return buttonBackgroundColor; | ||
| 87 | + let labelColor: Color; | ||
| 88 | + applySelectors(label, (lbl) => { | ||
| 89 | + labelColor = lbl.color; | ||
| 90 | + }); | ||
| 91 | + return labelColor; | ||
| 87 | 92 | } | |
| 88 | 93 | ||
| 89 | - let textFieldColor: Color; | ||
| 90 | 94 | export function getTextFieldColor(): Color { | |
| 91 | - if (!textFieldColor) { | ||
| 95 | + if (!textField) { | ||
| 92 | 96 | const TextField = require("ui/text-field").TextField; | |
| 93 | - const tf = new TextField(); | ||
| 94 | - applySelectors(tf); | ||
| 95 | - textFieldColor = tf.color; | ||
| 96 | - tf.onUnloaded(); | ||
| 97 | + textField = new TextField(); | ||
| 97 | 98 | } | |
| 98 | 99 | ||
| 100 | + let textFieldColor: Color; | ||
| 101 | + applySelectors(textField, (tf) => { | ||
| 102 | + textFieldColor = tf.color; | ||
| 103 | + }); | ||
| 99 | 104 | return textFieldColor; | |
| 100 | 105 | } | |
| 101 | 106 | ||
| 102 | - let labelColor: Color; | ||
| 103 | - // NOTE: This will fail if app.css is changed. | ||
| 104 | - export function getLabelColor(): Color { | ||
| 105 | - if (!labelColor) { | ||
| 106 | - const Label = require("ui/label").Label; | ||
| 107 | - let lbl = new Label(); | ||
| 108 | - applySelectors(lbl); | ||
| 109 | - labelColor = lbl.color; | ||
| 110 | - lbl.onUnloaded(); | ||
| 111 | - } | ||
| 112 | - | ||
| 113 | - return labelColor; | ||
| 114 | - } | ||
| 115 | - | ||
| 116 | 107 | export function isDialogOptions(arg): boolean { | |
| 117 | 108 | return arg && (arg.message || arg.title); | |
| 118 | 109 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,7 @@ | |||
| 2 | 2 | * Android specific dialogs functions implementation. | |
| 3 | 3 | */ | |
| 4 | 4 | import { DialogOptions, ConfirmOptions, PromptOptions, PromptResult, LoginOptions, LoginResult, ActionOptions } from "."; | |
| 5 | - import { getLabelColor, getButtonColor, getButtonBackgroundColor, isDialogOptions, inputType, ALERT, OK, CONFIRM, CANCEL, PROMPT, LOGIN } from "./dialogs-common"; | ||
| 5 | + import { getLabelColor, getButtonColors, isDialogOptions, inputType, ALERT, OK, CONFIRM, CANCEL, PROMPT, LOGIN } from "./dialogs-common"; | ||
| 6 | 6 | import { android as androidApp } from "../../application"; | |
| 7 | 7 | ||
| 8 | 8 | export * from "./dialogs-common"; | |
@@ -43,9 +43,9 @@ function showDialog(builder: android.app.AlertDialog.Builder) { | |||
| 43 | 43 | } | |
| 44 | 44 | } | |
| 45 | 45 | ||
| 46 | - let buttonColor = getButtonColor(); | ||
| 47 | - let buttonBackgroundColor = getButtonBackgroundColor(); | ||
| 48 | - if (buttonColor) { | ||
| 46 | + let { color, backgroundColor } = getButtonColors(); | ||
| 47 | + | ||
| 48 | + if (color) { | ||
| 49 | 49 | let buttons: android.widget.Button[] = []; | |
| 50 | 50 | for (let i = 0; i < 3; i++) { | |
| 51 | 51 | let id = dlg.getContext().getResources().getIdentifier("android:id/button" + i, null, null); | |
@@ -54,11 +54,11 @@ function showDialog(builder: android.app.AlertDialog.Builder) { | |||
| 54 | 54 | ||
| 55 | 55 | buttons.forEach(button => { | |
| 56 | 56 | if (button) { | |
| 57 | - if (buttonColor) { | ||
| 58 | - button.setTextColor(buttonColor.android); | ||
| 57 | + if (color) { | ||
| 58 | + button.setTextColor(color.android); | ||
| 59 | 59 | } | |
| 60 | - if (buttonBackgroundColor) { | ||
| 61 | - button.setBackgroundColor(buttonBackgroundColor.android); | ||
| 60 | + if (backgroundColor) { | ||
| 61 | + button.setBackgroundColor(backgroundColor.android); | ||
| 62 | 62 | } | |
| 63 | 63 | } | |
| 64 | 64 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,7 @@ | |||
| 3 | 3 | */ | |
| 4 | 4 | ||
| 5 | 5 | import { ConfirmOptions, PromptOptions, PromptResult, LoginOptions, LoginResult, ActionOptions } from "."; | |
| 6 | - import { getCurrentPage, getLabelColor, getButtonColor, getTextFieldColor, isDialogOptions, inputType, ALERT, OK, CONFIRM, CANCEL, PROMPT, LOGIN } from "./dialogs-common"; | ||
| 6 | + import { getCurrentPage, getLabelColor, getButtonColors, getTextFieldColor, isDialogOptions, inputType, ALERT, OK, CONFIRM, CANCEL, PROMPT, LOGIN } from "./dialogs-common"; | ||
| 7 | 7 | import { isString, isDefined, isFunction } from "../../utils/types"; | |
| 8 | 8 | ||
| 9 | 9 | export * from "./dialogs-common"; | |
@@ -162,13 +162,14 @@ export function login(arg: any): Promise<LoginResult> { | |||
| 162 | 162 | let passwordTextField: UITextField; | |
| 163 | 163 | let alertController = UIAlertController.alertControllerWithTitleMessagePreferredStyle(options.title, options.message, UIAlertControllerStyle.Alert); | |
| 164 | 164 | ||
| 165 | + let textFieldColor = getTextFieldColor(); | ||
| 166 | + | ||
| 165 | 167 | alertController.addTextFieldWithConfigurationHandler((arg: UITextField) => { | |
| 166 | 168 | arg.placeholder = "Login"; | |
| 167 | 169 | arg.text = isString(options.userName) ? options.userName : ""; | |
| 168 | 170 | ||
| 169 | - let color = getTextFieldColor(); | ||
| 170 | - if (color) { | ||
| 171 | - arg.textColor = arg.tintColor = color.ios; | ||
| 171 | + if (textFieldColor) { | ||
| 172 | + arg.textColor = arg.tintColor = textFieldColor.ios; | ||
| 172 | 173 | } | |
| 173 | 174 | }); | |
| 174 | 175 | ||
@@ -177,9 +178,8 @@ export function login(arg: any): Promise<LoginResult> { | |||
| 177 | 178 | arg.secureTextEntry = true; | |
| 178 | 179 | arg.text = isString(options.password) ? options.password : ""; | |
| 179 | 180 | ||
| 180 | - let color = getTextFieldColor(); | ||
| 181 | - if (color) { | ||
| 182 | - arg.textColor = arg.tintColor = color.ios; | ||
| 181 | + if (textFieldColor) { | ||
| 182 | + arg.textColor = arg.tintColor = textFieldColor.ios; | ||
| 183 | 183 | } | |
| 184 | 184 | }); | |
| 185 | 185 | ||
@@ -214,7 +214,7 @@ function showUIAlertController(alertController: UIAlertController) { | |||
| 214 | 214 | alertController.popoverPresentationController.permittedArrowDirections = 0; | |
| 215 | 215 | } | |
| 216 | 216 | ||
| 217 | - let color = getButtonColor(); | ||
| 217 | + let color = getButtonColors().color; | ||
| 218 | 218 | if (color) { | |
| 219 | 219 | alertController.view.tintColor = color.ios; | |
| 220 | 220 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments