diff --git a/tns-core-modules/ui/text-base/text-base.ios.ts b/tns-core-modules/ui/text-base/text-base.ios.ts index 6560adbe9..c53d2569f 100644 --- a/tns-core-modules/ui/text-base/text-base.ios.ts +++ b/tns-core-modules/ui/text-base/text-base.ios.ts @@ -5,10 +5,14 @@ import { textTransformProperty, letterSpacingProperty, colorProperty, fontInternalProperty, lineHeightProperty, FormattedString, Span, Color, isBold, resetSymbol } from "./text-base-common"; -import { isString } from "../../utils/types"; export * from "./text-base-common"; +import { isString } from "../../utils/types"; +import { ios } from "../../utils/utils"; + +const majorVersion = ios.MajorVersion; + export class TextBase extends TextBaseCommon { public nativeViewProtected: UITextField | UITextView | UILabel | UIButton; @@ -134,7 +138,7 @@ export class TextBase extends TextBaseCommon { paragraphStyle.lineSpacing = this.lineHeight; // make sure a possible previously set text alignment setting is not lost when line height is specified paragraphStyle.alignment = (this.nativeTextViewProtected).textAlignment; - if (this.nativeTextViewProtected instanceof UILabel) { + if (this.nativeTextViewProtected instanceof UILabel) { // make sure a possible previously set line break mode is not lost when line height is specified paragraphStyle.lineBreakMode = this.nativeTextViewProtected.lineBreakMode; } @@ -183,7 +187,7 @@ export class TextBase extends TextBaseCommon { paragraphStyle.lineSpacing = style.lineHeight; // make sure a possible previously set text alignment setting is not lost when line height is specified paragraphStyle.alignment = (this.nativeTextViewProtected).textAlignment; - if (this.nativeTextViewProtected instanceof UILabel) { + if (this.nativeTextViewProtected instanceof UILabel) { // make sure a possible previously set line break mode is not lost when line height is specified paragraphStyle.lineBreakMode = this.nativeTextViewProtected.lineBreakMode; } @@ -194,18 +198,20 @@ export class TextBase extends TextBaseCommon { dict.set(NSParagraphStyleAttributeName, paragraphStyle); } - if (style.color && (dict.size > 0 || isTextView)) { - dict.set(NSForegroundColorAttributeName, style.color.ios); + if (dict.size > 0 || isTextView) { + if (style.color) { + dict.set(NSForegroundColorAttributeName, style.color.ios); + } else if (majorVersion >= 13) { + dict.set(NSForegroundColorAttributeName, UIColor.labelColor); + } } const text = this.text; const string = (text === undefined || text === null) ? "" : text.toString(); const source = getTransformedText(string, this.textTransform); if (dict.size > 0 || isTextView) { - if (isTextView) { - // UITextView's font seems to change inside. - dict.set(NSFontAttributeName, this.nativeTextViewProtected.font); - } + // UITextView's font seems to change inside. + dict.set(NSFontAttributeName, this.nativeTextViewProtected.font); const result = NSMutableAttributedString.alloc().initWithString(source); result.setAttributesRange(dict, { location: 0, length: source.length }); diff --git a/tns-core-modules/ui/text-view/text-view.ios.ts b/tns-core-modules/ui/text-view/text-view.ios.ts index 0b14b8c74..6a357e115 100644 --- a/tns-core-modules/ui/text-view/text-view.ios.ts +++ b/tns-core-modules/ui/text-view/text-view.ios.ts @@ -8,10 +8,13 @@ import { CSSType } from "../editable-text-base"; -import { profile } from "../../profiling"; - export * from "../editable-text-base"; +import { profile } from "../../profiling"; +import { ios } from "../../utils/utils"; + +const majorVersion = ios.MajorVersion; + class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate { public static ObjCProtocols = [UITextViewDelegate]; @@ -113,6 +116,9 @@ export class TextView extends EditableTextBase implements TextViewDefinition { private _isShowingHint: boolean; public _isEditing: boolean; + private getHintColor = () => majorVersion <= 12 ? UIColor.blackColor.colorWithAlphaComponent(0.22) : UIColor.placeholderTextColor; + private getTextColor = () => majorVersion <= 12 ? null : UIColor.labelColor; + createNativeView() { const textView = NoScrollAnimationUITextView.new(); if (!textView.font) { @@ -173,7 +179,7 @@ export class TextView extends EditableTextBase implements TextViewDefinition { // Use semi-transparent version of color for back-compatibility this.nativeTextViewProtected.textColor = color.ios.colorWithAlphaComponent(0.22); } else { - this.nativeTextViewProtected.textColor = UIColor.blackColor.colorWithAlphaComponent(0.22); + this.nativeTextViewProtected.textColor = this.getHintColor(); } } else { const color = this.style.color; @@ -182,8 +188,8 @@ export class TextView extends EditableTextBase implements TextViewDefinition { this.nativeTextViewProtected.textColor = color.ios; this.nativeTextViewProtected.tintColor = color.ios; } else { - this.nativeTextViewProtected.textColor = null; - this.nativeTextViewProtected.tintColor = null; + this.nativeTextViewProtected.textColor = this.getTextColor(); + this.nativeTextViewProtected.tintColor = this.getTextColor(); } } } @@ -329,4 +335,4 @@ export class TextView extends EditableTextBase implements TextViewDefinition { } } -TextView.prototype.recycleNativeView = "auto"; \ No newline at end of file +TextView.prototype.recycleNativeView = "auto";