Skip to content

Commit 7837e47

Browse files
committed
fix: some color fixes
1 parent 6863572 commit 7837e47

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

src/label.android.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,11 @@ function initializeURLClickableSpan(): void {
186186
super.updateDrawState(tp);
187187
}
188188
if (owner && owner.linkColor) {
189-
tp.setColor(owner.linkColor.android);
189+
const color =
190+
!owner.linkColor || owner.linkColor instanceof Color
191+
? (owner.linkColor as Color)
192+
: new Color(owner.linkColor);
193+
tp.setColor(color.android);
190194
}
191195
}
192196
}
@@ -201,7 +205,7 @@ abstract class LabelBase extends View implements LabelViewDefinition {
201205
@cssProperty minFontSize: number;
202206
@cssProperty maxFontSize: number;
203207
@cssProperty verticalTextAlignment: VerticalTextAlignment;
204-
@cssProperty linkColor: Color;
208+
@cssProperty linkColor: Color | string;
205209
@cssProperty textShadow: CSSShadow;
206210
@cssProperty linkUnderline: boolean;
207211
public html: string;
@@ -419,11 +423,12 @@ export class Label extends LabelBase {
419423
view.setGravity(getHorizontalGravity(value) | getVerticalGravity(this.verticalTextAlignment));
420424
}
421425

422-
[colorProperty.setNative](value: Color | android.content.res.ColorStateList) {
423-
if (value instanceof Color) {
424-
this.nativeTextViewProtected.setTextColor(value.android);
426+
[colorProperty.setNative](value: Color | string) {
427+
const color = !value || value instanceof Color ? (value as Color) : new Color(value);
428+
if (color) {
429+
this.nativeTextViewProtected.setTextColor(color.android);
425430
} else {
426-
this.nativeTextViewProtected.setTextColor(value);
431+
this.nativeTextViewProtected.setTextColor(null);
427432
}
428433
}
429434
[fontSizeProperty.setNative](value: number | { nativeSize: number }) {

src/label.ios.ts

+15-13
Original file line numberDiff line numberDiff line change
@@ -486,23 +486,21 @@ export class Label extends LabelBase {
486486
}
487487
this._requestLayoutOnTextChanged();
488488
}
489-
[colorProperty.setNative](value: Color | UIColor) {
490-
const color = value instanceof Color ? value.ios : value;
491-
// if (!this.formattedText && !this.html) {
489+
[colorProperty.setNative](value: Color | string) {
490+
const color = !value || value instanceof Color ? (value as Color) : new Color(value);
492491
const nativeView = this.nativeTextViewProtected;
493-
nativeView.textColor = color;
494-
// }
492+
nativeView.textColor = color ? color.ios : null;
495493
}
496-
[linkColorProperty.setNative](value: Color | UIColor) {
497-
const color = value instanceof Color ? value.ios : value;
494+
[linkColorProperty.setNative](value: Color | string) {
495+
const color = !value || value instanceof Color ? (value as Color) : new Color(value);
498496
const nativeView = this.nativeTextViewProtected;
499497
let attributes = nativeView.linkTextAttributes;
500498
if (!(attributes instanceof NSMutableDictionary)) {
501499
attributes = NSMutableDictionary.new();
502500
}
503-
attributes.setValueForKey(color, NSForegroundColorAttributeName);
504-
if (this.linkUnderline !== false) {
505-
attributes.setValueForKey(color, NSUnderlineColorAttributeName);
501+
if (this.linkUnderline !== false && color) {
502+
attributes.setValueForKey(color.ios , NSForegroundColorAttributeName);
503+
attributes.setValueForKey(color.ios, NSUnderlineColorAttributeName);
506504
} else {
507505
attributes.setValueForKey(UIColor.clearColor, NSUnderlineColorAttributeName);
508506
}
@@ -518,8 +516,9 @@ export class Label extends LabelBase {
518516
attributes = NSMutableDictionary.new();
519517
}
520518
if (value) {
521-
if (this.linkColor) {
522-
attributes.setValueForKey(this.linkColor.ios, NSUnderlineColorAttributeName);
519+
const color = !this.linkColor || this.linkColor instanceof Color ? this.linkColor : new Color(this.linkColor);
520+
if (color) {
521+
attributes.setValueForKey(color.ios, NSUnderlineColorAttributeName);
523522
} else {
524523
attributes.removeObjectForKey(NSUnderlineColorAttributeName);
525524
}
@@ -607,7 +606,10 @@ export class Label extends LabelBase {
607606
dict.set(NSFontAttributeName, this.nativeTextViewProtected.font);
608607
}
609608
if (style.color) {
610-
dict.set(NSForegroundColorAttributeName, style.color.ios);
609+
const color = !style.color || style.color instanceof Color ? style.color : new Color(style.color);
610+
if (color) {
611+
dict.set(NSForegroundColorAttributeName, color.ios);
612+
}
611613
}
612614
const result = NSMutableAttributedString.alloc().initWithString(source);
613615
result.setAttributesRange(dict as any, {

0 commit comments

Comments
 (0)