From 333086d3d4eec9bf4f384bebc328993d12244f89 Mon Sep 17 00:00:00 2001 From: Dimitris - Rafail Katsampas Date: Thu, 20 Feb 2025 11:24:28 +0200 Subject: [PATCH 1/3] fix(ios): Corrected background color mismatch between Label and nested spans --- packages/core/ui/text-base/index.ios.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/ui/text-base/index.ios.ts b/packages/core/ui/text-base/index.ios.ts index 1b3aecab93..6bcd23da43 100644 --- a/packages/core/ui/text-base/index.ios.ts +++ b/packages/core/ui/text-base/index.ios.ts @@ -394,8 +394,8 @@ export class TextBase extends TextBaseCommon { const fontScale = adjustMinMaxFontScale(span.style.fontScaleInternal, span); const font = new Font(span.style.fontFamily, span.style.fontSize, span.style.fontStyle, span.style.fontWeight, fontScale, span.style.fontVariationSettings); const iosFont = font.getUIFont(this.nativeTextViewProtected.font); + const backgroundColor = span.style.backgroundColor; - const backgroundColor = (span.style.backgroundColor || (span.parent).backgroundColor || (span.parent.parent).backgroundColor); return { text, iosFont, From b12c28db578220012f64593ce4fe6ca85e65a00f Mon Sep 17 00:00:00 2001 From: Dimitris - Rafail Katsampas Date: Thu, 20 Feb 2025 14:39:58 +0200 Subject: [PATCH 2/3] fix: Use FormattedString background color as fallback --- packages/core/ui/text-base/index.android.ts | 6 ++++-- packages/core/ui/text-base/index.ios.ts | 3 ++- packages/core/ui/text-base/span.d.ts | 3 +++ packages/core/ui/text-base/span.ts | 6 +++++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/core/ui/text-base/index.android.ts b/packages/core/ui/text-base/index.android.ts index 8c3c9e82b4..fa785b7046 100644 --- a/packages/core/ui/text-base/index.android.ts +++ b/packages/core/ui/text-base/index.android.ts @@ -624,8 +624,10 @@ function setSpanModifiers(ssb: android.text.SpannableStringBuilder, span: Span, ssb.setSpan(new android.text.style.ForegroundColorSpan(color.android), start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } - if (spanStyle.backgroundColor) { - ssb.setSpan(new android.text.style.BackgroundColorSpan(spanStyle.backgroundColor.android), start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + // Use span or formatted string color + const backgroundColor = spanStyle.backgroundColor || span.parent.backgroundColor; + if (backgroundColor) { + ssb.setSpan(new android.text.style.BackgroundColorSpan(backgroundColor.android), start, end, android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } const textDecoration: CoreTypes.TextDecorationType = getClosestPropertyValue(textDecorationProperty, span); diff --git a/packages/core/ui/text-base/index.ios.ts b/packages/core/ui/text-base/index.ios.ts index 6bcd23da43..89a3b33197 100644 --- a/packages/core/ui/text-base/index.ios.ts +++ b/packages/core/ui/text-base/index.ios.ts @@ -394,7 +394,8 @@ export class TextBase extends TextBaseCommon { const fontScale = adjustMinMaxFontScale(span.style.fontScaleInternal, span); const font = new Font(span.style.fontFamily, span.style.fontSize, span.style.fontStyle, span.style.fontWeight, fontScale, span.style.fontVariationSettings); const iosFont = font.getUIFont(this.nativeTextViewProtected.font); - const backgroundColor = span.style.backgroundColor; + // Use span or formatted string color + const backgroundColor = span.style.backgroundColor || span.parent.backgroundColor; return { text, diff --git a/packages/core/ui/text-base/span.d.ts b/packages/core/ui/text-base/span.d.ts index 418c5ebb75..e543413644 100644 --- a/packages/core/ui/text-base/span.d.ts +++ b/packages/core/ui/text-base/span.d.ts @@ -2,6 +2,7 @@ import { ViewBase } from '../core/view-base'; import { FontStyleType, FontVariationSettingsType, FontWeightType } from '../styling/font'; import { CoreTypes } from '../../core-types'; +import { FormattedString } from './formatted-string'; /** * A class used to create a single part of formatted string with a common text properties. @@ -9,6 +10,8 @@ import { CoreTypes } from '../../core-types'; * @nsView Span */ export class Span extends ViewBase { + declare parent: FormattedString; + /** * Gets or sets the font family of the span. * diff --git a/packages/core/ui/text-base/span.ts b/packages/core/ui/text-base/span.ts index 006ba45de8..f94b1f604e 100644 --- a/packages/core/ui/text-base/span.ts +++ b/packages/core/ui/text-base/span.ts @@ -5,12 +5,16 @@ import { FontStyleType, FontVariationSettingsType, FontWeightType } from '../sty import { CoreTypes } from '../../core-types'; import { EventData } from '../../data/observable'; import { isNullOrUndefined, isString } from '../../utils/types'; +import type { FormattedString } from './formatted-string'; export class Span extends ViewBase implements SpanDefinition { - static linkTapEvent = 'linkTap'; + public static linkTapEvent = 'linkTap'; + private _text: string; private _tappable = false; + declare parent: FormattedString; + get fontFamily(): string { return this.style.fontFamily; } From 015c86505c91d1ff0e0f2f08e70c6a5060aaec16 Mon Sep 17 00:00:00 2001 From: Dimitris - Rafail Katsampas Date: Thu, 20 Feb 2025 14:46:39 +0200 Subject: [PATCH 3/3] chore: Minor type organization --- packages/core/ui/text-base/span.d.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/core/ui/text-base/span.d.ts b/packages/core/ui/text-base/span.d.ts index e543413644..c66c6771cd 100644 --- a/packages/core/ui/text-base/span.d.ts +++ b/packages/core/ui/text-base/span.d.ts @@ -10,6 +10,13 @@ import { FormattedString } from './formatted-string'; * @nsView Span */ export class Span extends ViewBase { + /** + * String value used when hooking to linkTap event. + * + * @nsEvent linkTap + */ + public static linkTapEvent: string; + declare parent: FormattedString; /** @@ -95,12 +102,6 @@ export class Span extends ViewBase { * @nsProperty */ public text: string; - /** - * String value used when hooking to linkTap event. - * - * @nsEvent linkTap - */ - public static linkTapEvent: string; /** * Gets if the span is tappable or not.