Skip to content

Commit 74726a8

Browse files
committed
fix(textfield): android fix stroke colors
1 parent f34a35a commit 74726a8

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

packages/core/platforms/android/java/com/nativescript/material/core/Utils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ public static void createStateListAnimator(Context context, View view, float ele
4545

4646
public static ColorStateList getEnabledColorStateList(int color, int disabledColor) {
4747
int[][] states = new int[][] { new int[] { -android.R.attr.state_enabled }, // enabled
48-
android.util.StateSet.NOTHING, // disabled
48+
android.util.StateSet.WILD_CARD, // disabled
4949
};
5050
int[] colors = new int[] { disabledColor, color };
5151
return new android.content.res.ColorStateList(states, colors);
5252
}
5353

5454
public static ColorStateList getFullColorStateList(int activeColor, int inactiveColor, int disabledColor) {
55-
int[][] states = new int[][] { new int[] { android.R.attr.state_focused }, // focused
56-
android.util.StateSet.NOTHING, // other
55+
int[][] states = new int[][] { new int[] { android.R.attr.state_focused, }, // focused
56+
android.util.StateSet.WILD_CARD, // other
5757
new int[] { -android.R.attr.state_enabled } // disabled
5858
};
5959
int[] colors = new int[] { activeColor, inactiveColor, disabledColor };

src/core/textbase/cssproperties.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export const strokeInactiveColorProperty = new CssProperty<Style, Color>({
6363
equalityComparer: Color.equals,
6464
valueConverter: v => new Color(v)
6565
});
66+
strokeInactiveColorProperty.register(Style);
6667
export const strokeDisabledColorProperty = new CssProperty<Style, Color>({
6768
name: 'strokeDisabledColor',
6869
cssName: 'stroke-disabled-color',

src/textfield/textfield.android.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,19 @@ export class TextField extends TextFieldBase {
127127
[placeholderColorProperty.setNative](value: Color) {
128128
const placeholderColor = value instanceof Color ? value.android : value;
129129
const floatingColor = this.floatingColor instanceof Color ? this.floatingColor.android : placeholderColor;
130-
131-
this.layoutView.setDefaultHintTextColor(getFullColorStateList(floatingColor, placeholderColor));
130+
this.layoutView.setHintTextColor(getFullColorStateList(floatingColor, placeholderColor));
132131
}
133132

134133
[floatingColorProperty.setNative](value: Color) {
135134
const floatingColor = value instanceof Color ? value.android : value;
136-
const placeholderColor = this.placeholderColor instanceof Color ? this.placeholderColor.android : undefined;
135+
const placeholderColor = this.floatingInactiveColor instanceof Color ? this.floatingInactiveColor.android : undefined;
137136
this.layoutView.setDefaultHintTextColor(getFullColorStateList(floatingColor, placeholderColor));
138137
}
139138

140139
[floatingInactiveColorProperty.setNative](value: Color) {
141-
const placeholderColor = value instanceof Color ? value.android : value;
140+
const floatingInactiveColor = value instanceof Color ? value.android : value;
142141
const floatingColor = (this.floatingColor || (themer.getPrimaryColor() as Color)).android;
143-
this.layoutView.setDefaultHintTextColor(getFullColorStateList(floatingColor, placeholderColor));
142+
this.layoutView.setDefaultHintTextColor(getFullColorStateList(floatingColor, floatingInactiveColor));
144143
}
145144
[helperColorProperty.setNative](value) {
146145
const color = value instanceof Color ? value.android : value;
@@ -208,27 +207,30 @@ export class TextField extends TextFieldBase {
208207
const color = value instanceof Color ? value.android : value;
209208
if (this.layoutView.setBoxStrokeColorStateList) {
210209
const activeColor = this.strokeColor instanceof Color ? this.strokeColor.android : this.layoutView.getBoxStrokeColor();
211-
const colorStateList = getFullColorStateList(activeColor, color);
210+
const disabledColor = this.strokeDisabledColor instanceof Color ? this.strokeDisabledColor.android : undefined;
211+
const colorStateList = getFullColorStateList(activeColor, color, disabledColor);
212212
this.layoutView.setBoxStrokeColorStateList(colorStateList);
213213
}
214214
}
215-
[strokeDisabledColorProperty.setNative](value: Color) {
215+
216+
[strokeColorProperty.setNative](value: Color) {
216217
const color = value instanceof Color ? value.android : value;
217218
if (this.layoutView.setBoxStrokeColorStateList) {
218-
const activeColor = this.strokeColor instanceof Color ? this.strokeColor.android : this.layoutView.getBoxStrokeColor();
219-
const colorStateList = getFullColorStateList(activeColor, color);
219+
const inactiveColor = this.strokeInactiveColor instanceof Color ? this.strokeInactiveColor.android : undefined;
220+
const disabledColor = this.strokeDisabledColor instanceof Color ? this.strokeDisabledColor.android : undefined;
221+
const colorStateList = getFullColorStateList(color, inactiveColor, disabledColor);
220222
this.layoutView.setBoxStrokeColorStateList(colorStateList);
223+
} else {
224+
this.layoutView.setBoxStrokeColor(color);
221225
}
222226
}
223-
224-
[strokeColorProperty.setNative](value: Color) {
227+
[strokeDisabledColorProperty.setNative](value: Color) {
225228
const color = value instanceof Color ? value.android : value;
226229
if (this.layoutView.setBoxStrokeColorStateList) {
230+
const activeColor = this.strokeColor instanceof Color ? this.strokeColor.android : this.layoutView.getBoxStrokeColor();
227231
const inactiveColor = this.strokeInactiveColor instanceof Color ? this.strokeInactiveColor.android : undefined;
228-
const colorStateList = getFullColorStateList(color, inactiveColor);
232+
const colorStateList = getFullColorStateList(activeColor, inactiveColor, color);
229233
this.layoutView.setBoxStrokeColorStateList(colorStateList);
230-
} else {
231-
this.layoutView.setBoxStrokeColor(color);
232234
}
233235
}
234236

0 commit comments

Comments
 (0)