feat(dark-mode): text-view colors

This commit is contained in:
Vasil Chimev
2019-09-15 11:15:02 +03:00
parent f3b643ed3f
commit 9be301b8c7
2 changed files with 27 additions and 15 deletions

View File

@@ -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 = (<UITextField | UITextView | UILabel>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 = (<UITextField | UITextView | UILabel>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(<any>dict, { location: 0, length: source.length });

View File

@@ -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";
TextView.prototype.recycleNativeView = "auto";