|
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 | } |
0 commit comments