Skip to content

Commit 520f1a6

Browse files
committed
fix(dialogs): drop default labels, titles, buttons colors
instead support options
1 parent 76b387d commit 520f1a6

File tree

2 files changed

+67
-34
lines changed

2 files changed

+67
-34
lines changed

src/dialogs/dialogs.android.ts

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,23 @@ import { getSystemCssClasses, MODAL_ROOT_VIEW_CSS_CLASS } from '@nativescript/co
33
import { fromObject } from '@nativescript/core/data/observable';
44
import { createViewFromEntry } from '@nativescript/core/ui/builder';
55
import { View } from '@nativescript/core/ui/core/view';
6-
import { ActionOptions, ALERT, CANCEL, capitalizationType, CONFIRM, ConfirmOptions, DialogOptions, getButtonColors, getLabelColor, inputType, LOGIN, LoginResult, OK, PROMPT, PromptResult } from '@nativescript/core/ui/dialogs';
6+
import {
7+
ActionOptions,
8+
ALERT,
9+
CANCEL,
10+
capitalizationType,
11+
CONFIRM,
12+
ConfirmOptions,
13+
DialogOptions,
14+
getButtonColors,
15+
getLabelColor,
16+
inputType,
17+
LOGIN,
18+
LoginResult,
19+
OK,
20+
PROMPT,
21+
PromptResult
22+
} from '@nativescript/core/ui/dialogs';
723
import { StackLayout } from '@nativescript/core/ui/layouts/stack-layout';
824
import { ad } from '@nativescript/core/utils/utils';
925
import { TextField } from 'nativescript-material-textfield';
@@ -48,7 +64,6 @@ function createAlertDialog(options?: DialogOptions & MDCAlertControlerOptions):
4864
moduleName: options.view as string
4965
});
5066

51-
5267
view.cssClasses.add(MODAL_ROOT_VIEW_CSS_CLASS);
5368
const modalRootViewCssClasses = getSystemCssClasses();
5469
modalRootViewCssClasses.forEach(c => view.cssClasses.add(c));
@@ -80,35 +95,58 @@ function showDialog(builder: androidx.appcompat.app.AlertDialog.Builder, options
8095
};
8196
view.bindingContext = fromObject(context);
8297
}
83-
84-
const labelColor = getLabelColor();
85-
if (labelColor) {
98+
if (options.titleColor) {
8699
const textViewId = dlg
87100
.getContext()
88101
.getResources()
89102
.getIdentifier('android:id/alertTitle', null, null);
90103
if (textViewId) {
91104
const tv = <android.widget.TextView>dlg.findViewById(textViewId);
92105
if (tv) {
93-
tv.setTextColor(labelColor.android);
106+
tv.setTextColor(options.titleColor.android);
94107
}
95108
}
96-
97-
const messageTextViewId = dlg
98-
.getContext()
99-
.getResources()
100-
.getIdentifier('android:id/message', null, null);
101-
if (messageTextViewId) {
102-
const messageTextView = <android.widget.TextView>dlg.findViewById(messageTextViewId);
103-
if (messageTextView) {
104-
messageTextView.setTextColor(labelColor.android);
109+
if (options.messageColor) {
110+
const messageTextViewId = dlg
111+
.getContext()
112+
.getResources()
113+
.getIdentifier('android:id/message', null, null);
114+
if (messageTextViewId) {
115+
const messageTextView = <android.widget.TextView>dlg.findViewById(messageTextViewId);
116+
if (messageTextView) {
117+
messageTextView.setTextColor(options.messageColor.android);
118+
}
105119
}
106120
}
107121
}
108-
109-
let { color, backgroundColor } = getButtonColors();
110-
111-
if (color) {
122+
// const labelColor = getLabelColor();
123+
// if (labelColor) {
124+
// const textViewId = dlg
125+
// .getContext()
126+
// .getResources()
127+
// .getIdentifier('android:id/alertTitle', null, null);
128+
// if (textViewId) {
129+
// const tv = <android.widget.TextView>dlg.findViewById(textViewId);
130+
// if (tv) {
131+
// tv.setTextColor(labelColor.android);
132+
// }
133+
// }
134+
135+
// const messageTextViewId = dlg
136+
// .getContext()
137+
// .getResources()
138+
// .getIdentifier('android:id/message', null, null);
139+
// if (messageTextViewId) {
140+
// const messageTextView = <android.widget.TextView>dlg.findViewById(messageTextViewId);
141+
// if (messageTextView) {
142+
// messageTextView.setTextColor(labelColor.android);
143+
// }
144+
// }
145+
// }
146+
147+
// let { color, backgroundColor } = getButtonColors();
148+
149+
if (options.buttonInkColor || options.buttonTitleColor) {
112150
let buttons: android.widget.Button[] = [];
113151
for (let i = 0; i < 3; i++) {
114152
let id = dlg
@@ -120,12 +158,7 @@ function showDialog(builder: androidx.appcompat.app.AlertDialog.Builder, options
120158

121159
buttons.forEach(button => {
122160
if (button) {
123-
if (color) {
124-
button.setTextColor(color.android);
125-
}
126-
if (backgroundColor) {
127-
button.setBackgroundColor(backgroundColor.android);
128-
}
161+
button.setTextColor((options.buttonInkColor || options.buttonTitleColor).android);
129162
}
130163
});
131164
}

src/dialogs/dialogs.ios.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,11 @@ function raiseCallback(callback, result) {
236236

237237
function createAlertController(options: DialogOptions & MDCAlertControlerOptions, resolve?: Function) {
238238
const alertController = (MDCAlertControllerImpl as any).new() as MDCAlertControllerImpl;
239-
const buttonColor = getButtonColors().color;
240-
if (buttonColor) {
241-
alertController.view.tintColor = buttonColor.ios;
242-
}
243-
const lblColor = getLabelColor();
239+
// const buttonColor = getButtonColors().color;
240+
// if (buttonColor) {
241+
// alertController.view.tintColor = buttonColor.ios;
242+
// }
243+
// const lblColor = getLabelColor();
244244

245245
if (options.title) {
246246
alertController.title = options.title;
@@ -268,16 +268,16 @@ function createAlertController(options: DialogOptions & MDCAlertControlerOptions
268268
}
269269
if (options.titleColor) {
270270
alertController.titleColor = options.titleColor.ios;
271-
} else if (lblColor) {
272-
alertController.titleColor = lblColor.ios;
271+
// } else if (lblColor) {
272+
// alertController.titleColor = lblColor.ios;
273273
}
274274
if (options.titleIconTintColor) {
275275
alertController.titleIconTintColor = options.titleIconTintColor.ios;
276276
}
277277
if (options.messageColor) {
278278
alertController.messageColor = options.messageColor.ios;
279-
} else if (lblColor) {
280-
alertController.messageColor = lblColor.ios;
279+
// } else if (lblColor) {
280+
// alertController.messageColor = lblColor.ios;
281281
}
282282
if (options.elevation) {
283283
alertController.elevation = options.elevation;

0 commit comments

Comments
 (0)