Skip to content

Commit 04a3a2a

Browse files
committed
fix(textview): ios fix color not working
1 parent dc21204 commit 04a3a2a

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

src/textview/textview.ios.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,21 @@ import {
1212
strokeColorProperty,
1313
strokeInactiveColorProperty,
1414
} from '@nativescript-community/ui-material-core/textbase/cssproperties';
15-
import { Background, Color, Property, Screen, Style, Utils, View, backgroundInternalProperty, editableProperty, hintProperty, isAndroid, placeholderColorProperty } from '@nativescript/core';
15+
import {
16+
Background,
17+
Color,
18+
Property,
19+
Screen,
20+
Style,
21+
Utils,
22+
View,
23+
backgroundInternalProperty,
24+
colorProperty,
25+
editableProperty,
26+
hintProperty,
27+
isAndroid,
28+
placeholderColorProperty,
29+
} from '@nativescript/core';
1630
import { resetSymbol, textProperty } from '@nativescript/core/ui/text-base';
1731
import { TextViewBase } from './textview.common';
1832

@@ -269,6 +283,34 @@ export class TextView extends TextViewBase {
269283
}
270284
}
271285

286+
// Override N textview to fix textColor : use nativeViewProtected instead of nativeTextViewProtected
287+
_isShowingHint: boolean;
288+
_textColor: UIColor;
289+
_hintColor: UIColor;
290+
_refreshColor() {
291+
if (this._isShowingHint) {
292+
const placeholderColor = this.style.placeholderColor;
293+
const color = this.style.color;
294+
if (placeholderColor) {
295+
this.nativeViewProtected.textColor = placeholderColor.ios;
296+
} else if (color) {
297+
// Use semi-transparent version of color for back-compatibility
298+
this.nativeViewProtected.textColor = color.ios.colorWithAlphaComponent(0.22);
299+
} else {
300+
this.nativeViewProtected.textColor = this._hintColor;
301+
}
302+
} else {
303+
const color = this.style.color;
304+
if (color) {
305+
this.nativeViewProtected.textColor = color.ios;
306+
this.nativeViewProtected.tintColor = color.ios;
307+
} else {
308+
this.nativeViewProtected.textColor = this._textColor;
309+
this.nativeViewProtected.tintColor = this._textColor;
310+
}
311+
}
312+
}
313+
272314
[hintProperty.getDefault](): string {
273315
return '';
274316
}

0 commit comments

Comments
 (0)