Skip to content

fix(core): Corrected background color between Label and nested spans #10701

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/core/ui/text-base/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion packages/core/ui/text-base/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,9 @@ 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);
// Use span or formatted string color
const backgroundColor = span.style.backgroundColor || span.parent.backgroundColor;

const backgroundColor = <Color>(span.style.backgroundColor || (<FormattedString>span.parent).backgroundColor || (<TextBase>span.parent.parent).backgroundColor);
return {
text,
iosFont,
Expand Down
16 changes: 10 additions & 6 deletions packages/core/ui/text-base/span.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@
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.
*
* @nsView Span
*/
export class Span extends ViewBase {
/**
* String value used when hooking to linkTap event.
*
* @nsEvent linkTap
*/
public static linkTapEvent: string;

declare parent: FormattedString;

/**
* Gets or sets the font family of the span.
*
Expand Down Expand Up @@ -92,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.
Expand Down
6 changes: 5 additions & 1 deletion packages/core/ui/text-base/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down