From cafe265f924179744fe0ab6fd9cc0454d71179cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Kie=C5=82b?= Date: Wed, 21 Oct 2026 13:14:44 +0200 Subject: [PATCH 01/18] feat(web): added border radius --- src/types.ts | 1 + src/web/styleConversion/buildMentionRulesCSS.ts | 1 + src/web/styleConversion/htmlStyleToCSSVariables.ts | 9 +++++++++ 3 files changed, 11 insertions(+) diff --git a/src/types.ts b/src/types.ts index fbe606487..78fe4db25 100644 --- a/src/types.ts +++ b/src/types.ts @@ -195,6 +195,7 @@ export interface MentionStyleProperties { color?: ColorValue; backgroundColor?: ColorValue; textDecorationLine?: 'underline' | 'none'; + borderRadius?: number; } export interface HtmlStyle { diff --git a/src/web/styleConversion/buildMentionRulesCSS.ts b/src/web/styleConversion/buildMentionRulesCSS.ts index b6785c174..aa41a0ba1 100644 --- a/src/web/styleConversion/buildMentionRulesCSS.ts +++ b/src/web/styleConversion/buildMentionRulesCSS.ts @@ -58,6 +58,7 @@ ${textSelector} { color: var(${ET_MENTION_CSS_VARS.color(indicator)}, var(${ET_MENTION_CSS_VARS.color(MENTION_STYLE_DEFAULT_KEY)})); background-color: var(${ET_MENTION_CSS_VARS.backgroundColor(indicator)}, var(${ET_MENTION_CSS_VARS.backgroundColor(MENTION_STYLE_DEFAULT_KEY)})); text-decoration-line: var(${ET_MENTION_CSS_VARS.textDecorationLine(indicator)}, var(${ET_MENTION_CSS_VARS.textDecorationLine(MENTION_STYLE_DEFAULT_KEY)})); + border-radius: var(${ET_MENTION_CSS_VARS.borderRadius(indicator)}, var(${ET_MENTION_CSS_VARS.borderRadius(MENTION_STYLE_DEFAULT_KEY)})); transition: none; }`.trim() ); diff --git a/src/web/styleConversion/htmlStyleToCSSVariables.ts b/src/web/styleConversion/htmlStyleToCSSVariables.ts index c25a4859a..ba3539661 100644 --- a/src/web/styleConversion/htmlStyleToCSSVariables.ts +++ b/src/web/styleConversion/htmlStyleToCSSVariables.ts @@ -117,6 +117,8 @@ export const ET_MENTION_CSS_VARS = { `--et-mention-${indicatorToMentionCssKey(indicator)}-background-color`, textDecorationLine: (indicator: string) => `--et-mention-${indicatorToMentionCssKey(indicator)}-text-decoration-line`, + borderRadius: (indicator: string) => + `--et-mention-${indicatorToMentionCssKey(indicator)}-border-radius`, } as const; function setColorVar( @@ -236,6 +238,13 @@ function applyMentionVars( vars[ET_MENTION_CSS_VARS.textDecorationLine(indicator)] = mentionStyle.textDecorationLine; } + if (mentionStyle.borderRadius != null) { + setPxVar( + vars, + ET_MENTION_CSS_VARS.borderRadius(indicator), + mentionStyle.borderRadius + ); + } } } From 58692ae42b522a7988c71a639b2c893115eee0c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Kie=C5=82b?= Date: Thu, 22 Oct 2026 16:11:20 +0200 Subject: [PATCH 02/18] feat: add rounded on android feat: rounded corners on ios --- .../gradle/gradle-daemon-jvm.properties | 12 ++++ apps/example/src/constants/editorConfig.ts | 1 + apps/example/src/constants/htmlStyle.ts | 1 + ios/EnrichedTextInputView.mm | 2 +- ios/EnrichedTextView.mm | 2 +- ios/extensions/LayoutManagerExtension.mm | 61 +++++++++++++++++++ ios/interfaces/MentionStyleProps.h | 5 ++ ios/interfaces/MentionStyleProps.mm | 9 +++ ios/styles/MentionStyle.mm | 8 ++- ios/utils/EnrichedTextTouchHandler.mm | 7 ++- 10 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 apps/example/android/gradle/gradle-daemon-jvm.properties diff --git a/apps/example/android/gradle/gradle-daemon-jvm.properties b/apps/example/android/gradle/gradle-daemon-jvm.properties new file mode 100644 index 000000000..fa4ed510e --- /dev/null +++ b/apps/example/android/gradle/gradle-daemon-jvm.properties @@ -0,0 +1,12 @@ +#This file is generated by updateDaemonJvm +toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/cf726b4a1c84b50457225f9bba6d7650/redirect +toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect +toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/cf726b4a1c84b50457225f9bba6d7650/redirect +toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect +toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/c2dd35c9d0aaf0ba6ad0791320f99dfc/redirect +toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/e5810bd7fd1f8a586644409d395a7e55/redirect +toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/cf726b4a1c84b50457225f9bba6d7650/redirect +toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect +toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/7b3c4877c0749019e6805bb61e421497/redirect +toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/d76df094a9cbbabd3b08251f9e61444a/redirect +toolchainVersion=25 diff --git a/apps/example/src/constants/editorConfig.ts b/apps/example/src/constants/editorConfig.ts index f29ac11c0..3d6f6f48e 100644 --- a/apps/example/src/constants/editorConfig.ts +++ b/apps/example/src/constants/editorConfig.ts @@ -113,6 +113,7 @@ export const htmlStyle = { color: 'green', backgroundColor: 'lightgreen', textDecorationLine: 'none', + borderRadius: 14, }, }, ol: { diff --git a/apps/example/src/constants/htmlStyle.ts b/apps/example/src/constants/htmlStyle.ts index 9bf3d790a..564ec8533 100644 --- a/apps/example/src/constants/htmlStyle.ts +++ b/apps/example/src/constants/htmlStyle.ts @@ -57,6 +57,7 @@ export const htmlStyle = { color: 'green', backgroundColor: 'lightgreen', textDecorationLine: 'none', + borderRadius: 14, }, }, ol: { diff --git a/ios/EnrichedTextInputView.mm b/ios/EnrichedTextInputView.mm index 7d4ba5593..a64569e0c 100644 --- a/ios/EnrichedTextInputView.mm +++ b/ios/EnrichedTextInputView.mm @@ -611,7 +611,7 @@ - (void)updateProps:(Props::Shared const &)props bool newSingleProps = NO; for (const auto &obj : newMentionStyle.items()) { - if (obj.second.isInt() || obj.second.isString()) { + if (obj.second.isNumber() || obj.second.isString()) { // we are in just a single MentionStyleProps object newSingleProps = YES; break; diff --git a/ios/EnrichedTextView.mm b/ios/EnrichedTextView.mm index 991b180c6..2aa0e706d 100644 --- a/ios/EnrichedTextView.mm +++ b/ios/EnrichedTextView.mm @@ -523,7 +523,7 @@ - (void)updateProps:(Props::Shared const &)props bool newSingleProps = NO; for (const auto &obj : newMentionStyle.items()) { - if (obj.second.isInt() || obj.second.isString()) { + if (obj.second.isNumber() || obj.second.isString()) { newSingleProps = YES; break; } else if (obj.second.isObject()) { diff --git a/ios/extensions/LayoutManagerExtension.mm b/ios/extensions/LayoutManagerExtension.mm index 19b19a120..5dcf07e85 100644 --- a/ios/extensions/LayoutManagerExtension.mm +++ b/ios/extensions/LayoutManagerExtension.mm @@ -1,6 +1,7 @@ #import "LayoutManagerExtension.h" #import "ColorExtension.h" #import "interfaces/EnrichedViewHost.h" +#import "interfaces/MentionStyleProps.h" #import "interfaces/StyleHeaders.h" #import "utils/RangeUtils.h" #import "utils/WeakBox.h" @@ -60,6 +61,66 @@ - (void)my_drawBackgroundForGlyphRange:(NSRange)glyphRange [self drawBlockQuotes:host origin:origin visibleCharRange:visibleCharRange]; [self drawLists:host origin:origin visibleCharRange:visibleCharRange]; [self drawCodeBlocks:host origin:origin visibleCharRange:visibleCharRange]; + [self drawMentionBackgrounds:host + origin:origin + visibleCharRange:visibleCharRange]; +} + +- (void)drawMentionBackgrounds:(id)host + origin:(CGPoint)origin + visibleCharRange:(NSRange)visibleCharRange { + NSTextStorage *textStorage = host.textView.textStorage; + NSMutableArray *ranges = [[NSMutableArray alloc] init]; + [textStorage enumerateAttribute:MentionRoundedBackgroundAttributeName + inRange:visibleCharRange + options:0 + usingBlock:^(id _Nullable value, NSRange range, + BOOL *_Nonnull stop) { + if (value != nullptr && range.length > 0) { + [ranges addObject:[NSValue valueWithRange:range]]; + } + }]; + + for (NSValue *rangeValue in ranges) { + NSRange range = [rangeValue rangeValue]; + MentionParams *params = [textStorage attribute:@"EnrichedMention" + atIndex:range.location + effectiveRange:nullptr]; + if (params == nullptr) { + continue; + } + MentionStyleProps *props = + [host.config mentionStylePropsForIndicator:params.indicator]; + UIColor *bgColor = + [textStorage attribute:MentionRoundedBackgroundAttributeName + atIndex:range.location + effectiveRange:nullptr]; + UIFont *font = [textStorage attribute:NSFontAttributeName + atIndex:range.location + effectiveRange:nullptr]; + [bgColor setFill]; + + NSRange glyphRange = [self glyphRangeForCharacterRange:range + actualCharacterRange:nullptr]; + // one rect per line in case the mention wraps + [self + enumerateEnclosingRectsForGlyphRange:glyphRange + withinSelectedGlyphRange:NSMakeRange(NSNotFound, 0) + inTextContainer:host.textView.textContainer + usingBlock:^(CGRect rect, BOOL *stop) { + CGRect bgRect = + [self getTextAlignedUsedRect:rect + font:font]; + bgRect.origin.x += origin.x; + bgRect.origin.y += origin.y; + CGFloat radius = + MIN(props.borderRadius, + bgRect.size.height / 2); + [[UIBezierPath + bezierPathWithRoundedRect:bgRect + cornerRadius:radius] fill]; + }]; + } } - (void)drawCodeBlocks:(id)host diff --git a/ios/interfaces/MentionStyleProps.h b/ios/interfaces/MentionStyleProps.h index f83d1bc40..d8d166c58 100644 --- a/ios/interfaces/MentionStyleProps.h +++ b/ios/interfaces/MentionStyleProps.h @@ -4,10 +4,15 @@ #import #import +// holds the mention's background color when it should be drawn with rounded +// corners by the layout manager instead of NSBackgroundColorAttributeName +extern NSString *const MentionRoundedBackgroundAttributeName; + @interface MentionStyleProps : NSObject @property UIColor *color; @property UIColor *backgroundColor; @property TextDecorationLineEnum decorationLine; +@property CGFloat borderRadius; + (NSDictionary *)getSinglePropsFromFollyDynamic:(folly::dynamic)folly; + (NSDictionary *)getComplexPropsFromFollyDynamic:(folly::dynamic)folly; diff --git a/ios/interfaces/MentionStyleProps.mm b/ios/interfaces/MentionStyleProps.mm index eddc29f1c..3855922c2 100644 --- a/ios/interfaces/MentionStyleProps.mm +++ b/ios/interfaces/MentionStyleProps.mm @@ -2,6 +2,9 @@ #import "extensions/StringExtension.h" #import +NSString *const MentionRoundedBackgroundAttributeName = + @"EnrichedMentionRoundedBackground"; + @implementation MentionStyleProps + (MentionStyleProps *)getSingleMentionStylePropsFromFollyDynamic: @@ -34,6 +37,12 @@ + (MentionStyleProps *)getSingleMentionStylePropsFromFollyDynamic: nativeProps.decorationLine = DecorationUnderline; } + if (folly["borderRadius"].isNumber()) { + nativeProps.borderRadius = folly["borderRadius"].asDouble(); + } else { + nativeProps.borderRadius = 0; + } + // text only if (folly["pressColor"].isNumber()) { facebook::react::SharedColor pressColor = facebook::react::SharedColor( diff --git a/ios/styles/MentionStyle.mm b/ios/styles/MentionStyle.mm index aa625c960..ac37c8b5a 100644 --- a/ios/styles/MentionStyle.mm +++ b/ios/styles/MentionStyle.mm @@ -55,10 +55,14 @@ - (void)applyStyling:(NSRange)range { NSForegroundColorAttributeName : styleProps.color, NSUnderlineColorAttributeName : styleProps.color, NSStrikethroughColorAttributeName : styleProps.color, - NSBackgroundColorAttributeName : - [styleProps.backgroundColor colorWithResolvedAlpha], } mutableCopy]; + // rounded backgrounds are drawn by the layout manager + NSAttributedStringKey bgKey = styleProps.borderRadius > 0 + ? MentionRoundedBackgroundAttributeName + : NSBackgroundColorAttributeName; + newAttrs[bgKey] = [styleProps.backgroundColor colorWithResolvedAlpha]; + if (styleProps.decorationLine == DecorationUnderline) { newAttrs[NSUnderlineStyleAttributeName] = @(NSUnderlineStyleSingle); } diff --git a/ios/utils/EnrichedTextTouchHandler.mm b/ios/utils/EnrichedTextTouchHandler.mm index c5b9cad69..c83cc26c2 100644 --- a/ios/utils/EnrichedTextTouchHandler.mm +++ b/ios/utils/EnrichedTextTouchHandler.mm @@ -103,6 +103,7 @@ - (void)updateVisualsPressed:(BOOL)pressed { if (pressed) { UIColor *color = nil; UIColor *bgColor = nil; + NSAttributedStringKey bgKey = NSBackgroundColorAttributeName; if ([_activeAttrKey isEqualToString:@"EnrichedMention"]) { MentionParams *m = (MentionParams *)_activeValue; @@ -110,6 +111,9 @@ - (void)updateVisualsPressed:(BOOL)pressed { [self.view.config mentionStylePropsForIndicator:m.indicator]; color = [mProps pressColor]; bgColor = [mProps pressBackgroundColor]; + if (mProps.borderRadius > 0) { + bgKey = MentionRoundedBackgroundAttributeName; + } } else { color = [self.view.config linkPressColor]; } @@ -121,8 +125,7 @@ - (void)updateVisualsPressed:(BOOL)pressed { newAttrs[NSStrikethroughColorAttributeName] = color; } if (bgColor) { - newAttrs[NSBackgroundColorAttributeName] = - [bgColor colorWithResolvedAlpha]; + newAttrs[bgKey] = [bgColor colorWithResolvedAlpha]; } [self.view.textView.textStorage addAttributes:newAttrs range:_activeRange]; From a8d4924f99dd3217e31568d158c1ea0ed1e7dbe7 Mon Sep 17 00:00:00 2001 From: relextm19 Date: Tue, 3 Nov 2026 15:06:30 +0100 Subject: [PATCH 03/18] feat(ios): corners only round at the start and end of a wrapped mention --- ios/extensions/LayoutManagerExtension.mm | 49 ++++++++++++++++-------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/ios/extensions/LayoutManagerExtension.mm b/ios/extensions/LayoutManagerExtension.mm index 5dcf07e85..5f32216cf 100644 --- a/ios/extensions/LayoutManagerExtension.mm +++ b/ios/extensions/LayoutManagerExtension.mm @@ -103,23 +103,38 @@ - (void)drawMentionBackgrounds:(id)host NSRange glyphRange = [self glyphRangeForCharacterRange:range actualCharacterRange:nullptr]; // one rect per line in case the mention wraps - [self - enumerateEnclosingRectsForGlyphRange:glyphRange - withinSelectedGlyphRange:NSMakeRange(NSNotFound, 0) - inTextContainer:host.textView.textContainer - usingBlock:^(CGRect rect, BOOL *stop) { - CGRect bgRect = - [self getTextAlignedUsedRect:rect - font:font]; - bgRect.origin.x += origin.x; - bgRect.origin.y += origin.y; - CGFloat radius = - MIN(props.borderRadius, - bgRect.size.height / 2); - [[UIBezierPath - bezierPathWithRoundedRect:bgRect - cornerRadius:radius] fill]; - }]; + NSMutableArray *lineRects = [[NSMutableArray alloc] init]; + [self enumerateEnclosingRectsForGlyphRange:glyphRange + withinSelectedGlyphRange:NSMakeRange(NSNotFound, 0) + inTextContainer:host.textView.textContainer + usingBlock:^(CGRect rect, BOOL *stop) { + [lineRects + addObject:[NSValue + valueWithCGRect:rect]]; + }]; + + // only the mention's start and end get rounded, so a wrapped mention + // still has 4 rounded corners in total + for (NSUInteger i = 0; i < lineRects.count; i++) { + CGRect bgRect = [self getTextAlignedUsedRect:[lineRects[i] CGRectValue] + font:font]; + bgRect.origin.x += origin.x; + bgRect.origin.y += origin.y; + + UIRectCorner corners = 0; + if (i == 0) { + corners |= UIRectCornerTopLeft | UIRectCornerBottomLeft; + } + if (i == lineRects.count - 1) { + corners |= UIRectCornerTopRight | UIRectCornerBottomRight; + } + + CGFloat radius = MIN(props.borderRadius, bgRect.size.height / 2); + [[UIBezierPath bezierPathWithRoundedRect:bgRect + byRoundingCorners:corners + cornerRadii:CGSizeMake(radius, radius)] + fill]; + } } } From 785670fc05f710f205d5107c17ffc0b1b60352d6 Mon Sep 17 00:00:00 2001 From: relextm19 Date: Wed, 4 Nov 2026 09:32:51 +0100 Subject: [PATCH 04/18] refactor(ios): remove obsolete operation --- ios/extensions/LayoutManagerExtension.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/extensions/LayoutManagerExtension.mm b/ios/extensions/LayoutManagerExtension.mm index 5f32216cf..c59da7a14 100644 --- a/ios/extensions/LayoutManagerExtension.mm +++ b/ios/extensions/LayoutManagerExtension.mm @@ -123,7 +123,7 @@ - (void)drawMentionBackgrounds:(id)host UIRectCorner corners = 0; if (i == 0) { - corners |= UIRectCornerTopLeft | UIRectCornerBottomLeft; + corners = UIRectCornerTopLeft | UIRectCornerBottomLeft; } if (i == lineRects.count - 1) { corners |= UIRectCornerTopRight | UIRectCornerBottomRight; From 80989587788b2954a45c27654af8611fefe62230 Mon Sep 17 00:00:00 2001 From: relextm19 Date: Wed, 4 Nov 2026 19:19:01 +0100 Subject: [PATCH 05/18] feat(android): add border radius to mentions --- .../common/MentionBackgroundDrawer.kt | 94 +++++++++++++++++++ .../swmansion/enriched/common/MentionStyle.kt | 1 + .../common/spans/EnrichedMentionSpan.kt | 1 - .../enriched/text/EnrichedTextStyle.kt | 4 +- .../enriched/text/EnrichedTextView.kt | 23 +++++ .../text/spans/EnrichedTextMentionSpan.kt | 8 -- .../textinput/EnrichedTextInputView.kt | 15 +++ .../enriched/textinput/styles/HtmlStyle.kt | 3 +- src/utils/defaultHtmlStyle.ts | 1 + 9 files changed, 139 insertions(+), 11 deletions(-) create mode 100644 android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt diff --git a/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt b/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt new file mode 100644 index 000000000..01319e0cc --- /dev/null +++ b/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt @@ -0,0 +1,94 @@ +package com.swmansion.enriched.common + +import android.graphics.Canvas +import android.graphics.Color +import android.graphics.Paint +import android.graphics.Path +import android.graphics.RectF +import android.text.Layout +import android.text.Spanned +import com.swmansion.enriched.common.spans.EnrichedMentionSpan +import kotlin.math.max +import kotlin.math.min + +// Mention backgrounds are drawn by the view instead of the span, because spans only get whole-line +// bounds and cannot round the corners of a single mention. +object MentionBackgroundDrawer { + private val paint = Paint(Paint.ANTI_ALIAS_FLAG) + private val path = Path() + private val rect = RectF() + private val radii = FloatArray(8) + + // Must be called with the canvas translated to the layout origin, before the text is drawn. + fun draw( + canvas: Canvas, + layout: Layout, + text: Spanned, + style: EnrichedStyle, + backgroundColorFor: (EnrichedMentionSpan, MentionStyle) -> Int = { _, mentionStyle -> mentionStyle.backgroundColor }, + ) { + val spans = text.getSpans(0, text.length, EnrichedMentionSpan::class.java) + for (span in spans) { + val mentionStyle = style.mentionsStyle[span.getIndicator()] ?: continue + val color = backgroundColorFor(span, mentionStyle) + if (Color.alpha(color) == 0) continue + + val start = text.getSpanStart(span) + val end = text.getSpanEnd(span) + if (start < 0 || end <= start) continue + + paint.color = color + drawSpanBackground(canvas, layout, start, end, mentionStyle.borderRadius) + } + } + + private fun drawSpanBackground( + canvas: Canvas, + layout: Layout, + start: Int, + end: Int, + radius: Float, + ) { + val firstLine = layout.getLineForOffset(start) + val lastLine = layout.getLineForOffset(end - 1) + + for (line in firstLine..lastLine) { + val isFirst = line == firstLine + val isLast = line == lastLine + + val segmentStart = if (isFirst) layout.getPrimaryHorizontal(start) else layout.getLineLeft(line) + val segmentEnd = + if (isLast) { + //if the end offset is at the start of a new line take the right edge of the line + layout.getPrimaryHorizontal(end).takeIf { layout.getLineForOffset(end) == line } ?: layout.getLineRight(line) + } else { + layout.getLineRight(line) + } + + rect.set( + segmentStart, + layout.getLineTop(line).toFloat(), + segmentEnd, + layout.getLineBottom(line).toFloat(), + ) + if (rect.width() <= 0f) continue + + // Only round the outer ends of a wrapped mention. + val leftRadius = if (isFirst) radius else 0f + val rightRadius = if (isLast) radius else 0f + // Corner order: top-left, top-right, bottom-right, bottom-left + radii[0] = leftRadius + radii[1] = leftRadius + radii[2] = rightRadius + radii[3] = rightRadius + radii[4] = rightRadius + radii[5] = rightRadius + radii[6] = leftRadius + radii[7] = leftRadius + + path.reset() + path.addRoundRect(rect, radii, Path.Direction.CW) + canvas.drawPath(path, paint) + } + } +} diff --git a/android/src/main/java/com/swmansion/enriched/common/MentionStyle.kt b/android/src/main/java/com/swmansion/enriched/common/MentionStyle.kt index e5a7d7c13..970866160 100644 --- a/android/src/main/java/com/swmansion/enriched/common/MentionStyle.kt +++ b/android/src/main/java/com/swmansion/enriched/common/MentionStyle.kt @@ -4,6 +4,7 @@ data class MentionStyle( val color: Int, val backgroundColor: Int, val underline: Boolean, + val borderRadius: Float = 0f, val pressColor: Int? = null, val pressBackgroundColor: Int? = null, ) diff --git a/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedMentionSpan.kt b/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedMentionSpan.kt index e323ecb72..a8e028bec 100644 --- a/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedMentionSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedMentionSpan.kt @@ -23,7 +23,6 @@ open class EnrichedMentionSpan( val mentionsStyle = enrichedStyle.mentionsStyle[indicator] ?: return textPaint.color = mentionsStyle.color - textPaint.bgColor = mentionsStyle.backgroundColor textPaint.isUnderlineText = mentionsStyle.underline } diff --git a/android/src/main/java/com/swmansion/enriched/text/EnrichedTextStyle.kt b/android/src/main/java/com/swmansion/enriched/text/EnrichedTextStyle.kt index 05281984a..0dde05c4c 100644 --- a/android/src/main/java/com/swmansion/enriched/text/EnrichedTextStyle.kt +++ b/android/src/main/java/com/swmansion/enriched/text/EnrichedTextStyle.kt @@ -120,7 +120,7 @@ data class EnrichedTextStyle( codeBlockRadius = parseFloat(codeblock, "borderRadius", allowFontScaling), inlineCodeColor = parseColor(context, inlineCode, "color"), inlineCodeBackgroundColor = parseColorWithOpacity(context, inlineCode, "backgroundColor"), - mentionsStyle = parseMentionsStyle(context, mentions), + mentionsStyle = parseMentionsStyle(context, mentions, allowFontScaling), allowFontScaling = allowFontScaling, ) } @@ -183,6 +183,7 @@ data class EnrichedTextStyle( private fun parseMentionsStyle( context: ReactContext, map: ReadableMap?, + allowFontScaling: Boolean, ): Map { val result = mutableMapOf() val iterator = map?.keySetIterator() ?: return result @@ -195,6 +196,7 @@ data class EnrichedTextStyle( color = parseColor(context, value, "color"), backgroundColor = parseColorWithOpacity(context, value, "backgroundColor"), underline = parseIsUnderline(value), + borderRadius = parseFloat(value, "borderRadius", allowFontScaling), pressColor = parseColor(context, value, "pressColor"), pressBackgroundColor = parseColorWithOpacity(context, value, "pressBackgroundColor"), ) diff --git a/android/src/main/java/com/swmansion/enriched/text/EnrichedTextView.kt b/android/src/main/java/com/swmansion/enriched/text/EnrichedTextView.kt index 3b92a2d08..efcb9fde5 100644 --- a/android/src/main/java/com/swmansion/enriched/text/EnrichedTextView.kt +++ b/android/src/main/java/com/swmansion/enriched/text/EnrichedTextView.kt @@ -3,6 +3,7 @@ package com.swmansion.enriched.text import android.content.ClipData import android.content.ClipboardManager import android.content.Context +import android.graphics.Canvas import android.graphics.Color import android.graphics.text.LineBreaker import android.os.Build @@ -25,6 +26,7 @@ import com.facebook.react.views.text.ReactTypefaceUtils.parseFontWeight import com.swmansion.enriched.common.EnrichedConstants import com.swmansion.enriched.common.EnrichedSpanFlags import com.swmansion.enriched.common.GumboNormalizer +import com.swmansion.enriched.common.MentionBackgroundDrawer import com.swmansion.enriched.common.parser.EnrichedParser import com.swmansion.enriched.common.pixelFromSpOrDp import com.swmansion.enriched.text.spans.EnrichedTextImageSpan @@ -92,6 +94,27 @@ class EnrichedTextView : AppCompatTextView { setFontSize(EnrichedConstants.TEXT_DEFAULT_FONT_SIZE) } + override fun onDraw(canvas: Canvas) { + val currentLayout = layout + val spanned = text as? Spanned + val style = enrichedStyle + if (currentLayout != null && spanned != null && style != null) { + canvas.save() + canvas.translate(totalPaddingLeft.toFloat(), totalPaddingTop.toFloat()) + MentionBackgroundDrawer.draw(canvas, currentLayout, spanned, style) { span, mentionStyle -> + val isPressed = (span as? EnrichedTextClickableSpan)?.isPressed == true + if (isPressed && mentionStyle.pressBackgroundColor != null) { + mentionStyle.pressBackgroundColor + } else { + mentionStyle.backgroundColor + } + } + canvas.restore() + } + + super.onDraw(canvas) + } + override fun onTouchEvent(event: MotionEvent): Boolean { val spanned = text as? Spanned val action = event.action diff --git a/android/src/main/java/com/swmansion/enriched/text/spans/EnrichedTextMentionSpan.kt b/android/src/main/java/com/swmansion/enriched/text/spans/EnrichedTextMentionSpan.kt index 9d49d988e..6abc8d3bb 100644 --- a/android/src/main/java/com/swmansion/enriched/text/spans/EnrichedTextMentionSpan.kt +++ b/android/src/main/java/com/swmansion/enriched/text/spans/EnrichedTextMentionSpan.kt @@ -35,15 +35,7 @@ class EnrichedTextMentionSpan( mentionsStyle.color } - val bgColor = - if (isPressed && mentionsStyle.pressBackgroundColor != null) { - mentionsStyle.pressBackgroundColor - } else { - mentionsStyle.backgroundColor - } - textPaint.color = color - textPaint.bgColor = bgColor } override fun onClick(view: View) { diff --git a/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputView.kt b/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputView.kt index 7e7342731..31d9bee22 100644 --- a/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputView.kt +++ b/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputView.kt @@ -5,6 +5,7 @@ import android.content.ClipboardManager import android.content.Context import android.graphics.BlendMode import android.graphics.BlendModeColorFilter +import android.graphics.Canvas import android.graphics.Color import android.graphics.Rect import android.graphics.text.LineBreaker @@ -41,6 +42,7 @@ import com.facebook.react.views.text.ReactTypefaceUtils.parseFontWeight import com.swmansion.enriched.common.EnrichedConstants import com.swmansion.enriched.common.EnrichedSpanFlags import com.swmansion.enriched.common.GumboNormalizer +import com.swmansion.enriched.common.MentionBackgroundDrawer import com.swmansion.enriched.common.parser.EnrichedParser import com.swmansion.enriched.common.pixelFromSpOrDp import com.swmansion.enriched.textinput.events.MentionHandler @@ -293,6 +295,19 @@ class EnrichedTextInputView : ) } + override fun onDraw(canvas: Canvas) { + val currentLayout = layout + val currentText = text + if (currentLayout != null && currentText != null) { + canvas.save() + canvas.translate(totalPaddingLeft.toFloat(), totalPaddingTop.toFloat()) + MentionBackgroundDrawer.draw(canvas, currentLayout, currentText, htmlStyle) + canvas.restore() + } + + super.onDraw(canvas) + } + // https://github.com/facebook/react-native/blob/36df97f500aa0aa8031098caf7526db358b6ddc1/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.kt#L295C1-L296C1 override fun onTouchEvent(ev: MotionEvent): Boolean { when (ev.action) { diff --git a/android/src/main/java/com/swmansion/enriched/textinput/styles/HtmlStyle.kt b/android/src/main/java/com/swmansion/enriched/textinput/styles/HtmlStyle.kt index 5a67113a5..9e0a83281 100644 --- a/android/src/main/java/com/swmansion/enriched/textinput/styles/HtmlStyle.kt +++ b/android/src/main/java/com/swmansion/enriched/textinput/styles/HtmlStyle.kt @@ -247,7 +247,8 @@ class HtmlStyle : EnrichedStyle { val color = parseColor(value, "color") val backgroundColor = parseColorWithOpacity(value, "backgroundColor") val isUnderline = parseIsUnderline(value) - val parsedStyle = MentionStyle(color, backgroundColor, isUnderline) + val borderRadius = parseFloat(value, "borderRadius") + val parsedStyle = MentionStyle(color, backgroundColor, isUnderline, borderRadius) parsedMentionsStyle.put(key, parsedStyle) } diff --git a/src/utils/defaultHtmlStyle.ts b/src/utils/defaultHtmlStyle.ts index 06666b7ad..dacb015af 100644 --- a/src/utils/defaultHtmlStyle.ts +++ b/src/utils/defaultHtmlStyle.ts @@ -49,6 +49,7 @@ export const DEFAULT_HTML_STYLE: Required = { color: 'blue', backgroundColor: 'yellow', textDecorationLine: 'underline', + borderRadius: 0, }, ol: { gapWidth: 16, From b488fb1f85d94801cff3fe56daf87867214461a1 Mon Sep 17 00:00:00 2001 From: relextm19 Date: Wed, 4 Nov 2026 23:15:05 +0100 Subject: [PATCH 06/18] refactor(android): remove obsolete code --- .../common/MentionBackgroundDrawer.kt | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt b/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt index 01319e0cc..78a010a61 100644 --- a/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt +++ b/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt @@ -8,8 +8,6 @@ import android.graphics.RectF import android.text.Layout import android.text.Spanned import com.swmansion.enriched.common.spans.EnrichedMentionSpan -import kotlin.math.max -import kotlin.math.min // Mention backgrounds are drawn by the view instead of the span, because spans only get whole-line // bounds and cannot round the corners of a single mention. @@ -21,11 +19,13 @@ object MentionBackgroundDrawer { // Must be called with the canvas translated to the layout origin, before the text is drawn. fun draw( - canvas: Canvas, - layout: Layout, - text: Spanned, - style: EnrichedStyle, - backgroundColorFor: (EnrichedMentionSpan, MentionStyle) -> Int = { _, mentionStyle -> mentionStyle.backgroundColor }, + canvas: Canvas, + layout: Layout, + text: Spanned, + style: EnrichedStyle, + backgroundColorFor: (EnrichedMentionSpan, MentionStyle) -> Int = { _, mentionStyle -> + mentionStyle.backgroundColor + }, ) { val spans = text.getSpans(0, text.length, EnrichedMentionSpan::class.java) for (span in spans) { @@ -43,11 +43,11 @@ object MentionBackgroundDrawer { } private fun drawSpanBackground( - canvas: Canvas, - layout: Layout, - start: Int, - end: Int, - radius: Float, + canvas: Canvas, + layout: Layout, + start: Int, + end: Int, + radius: Float, ) { val firstLine = layout.getLineForOffset(start) val lastLine = layout.getLineForOffset(end - 1) @@ -56,27 +56,27 @@ object MentionBackgroundDrawer { val isFirst = line == firstLine val isLast = line == lastLine - val segmentStart = if (isFirst) layout.getPrimaryHorizontal(start) else layout.getLineLeft(line) + val segmentStart = + if (isFirst) layout.getPrimaryHorizontal(start) else layout.getLineLeft(line) val segmentEnd = - if (isLast) { - //if the end offset is at the start of a new line take the right edge of the line - layout.getPrimaryHorizontal(end).takeIf { layout.getLineForOffset(end) == line } ?: layout.getLineRight(line) - } else { - layout.getLineRight(line) - } + if (isLast) { + layout.getPrimaryHorizontal(end) + } else { + layout.getLineRight(line) + } rect.set( - segmentStart, - layout.getLineTop(line).toFloat(), - segmentEnd, - layout.getLineBottom(line).toFloat(), + segmentStart, + layout.getLineTop(line).toFloat(), + segmentEnd, + layout.getLineBottom(line).toFloat(), ) if (rect.width() <= 0f) continue // Only round the outer ends of a wrapped mention. val leftRadius = if (isFirst) radius else 0f val rightRadius = if (isLast) radius else 0f - // Corner order: top-left, top-right, bottom-right, bottom-left + // Corner order: top-left, top-right, bottom-right, bottom-left radii[0] = leftRadius radii[1] = leftRadius radii[2] = rightRadius From 7756fe072e1871218d28b84c46dd1a64aadbbdee Mon Sep 17 00:00:00 2001 From: relextm19 Date: Wed, 4 Nov 2026 23:51:25 +0100 Subject: [PATCH 07/18] refactor: revert branch unrelated changes --- .../android/gradle/gradle-daemon-jvm.properties | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 apps/example/android/gradle/gradle-daemon-jvm.properties diff --git a/apps/example/android/gradle/gradle-daemon-jvm.properties b/apps/example/android/gradle/gradle-daemon-jvm.properties deleted file mode 100644 index fa4ed510e..000000000 --- a/apps/example/android/gradle/gradle-daemon-jvm.properties +++ /dev/null @@ -1,12 +0,0 @@ -#This file is generated by updateDaemonJvm -toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/cf726b4a1c84b50457225f9bba6d7650/redirect -toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect -toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/cf726b4a1c84b50457225f9bba6d7650/redirect -toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect -toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/c2dd35c9d0aaf0ba6ad0791320f99dfc/redirect -toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/e5810bd7fd1f8a586644409d395a7e55/redirect -toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/cf726b4a1c84b50457225f9bba6d7650/redirect -toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/fa1e318c287360478e3c83a9a3ef1007/redirect -toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/7b3c4877c0749019e6805bb61e421497/redirect -toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/d76df094a9cbbabd3b08251f9e61444a/redirect -toolchainVersion=25 From 11a62f2752aefe8e367afbeb99b4d4bda90d661d Mon Sep 17 00:00:00 2001 From: relextm19 Date: Thu, 5 Nov 2026 11:05:40 +0100 Subject: [PATCH 08/18] refactor: cleanup --- .../swmansion/enriched/common/MentionBackgroundDrawer.kt | 9 +++++---- apps/example-web/src/defaultHtmlStyle.ts | 1 + apps/example/src/constants/editorConfig.ts | 2 +- apps/example/src/constants/htmlStyle.ts | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt b/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt index 78a010a61..d13610400 100644 --- a/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt +++ b/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt @@ -25,7 +25,7 @@ object MentionBackgroundDrawer { style: EnrichedStyle, backgroundColorFor: (EnrichedMentionSpan, MentionStyle) -> Int = { _, mentionStyle -> mentionStyle.backgroundColor - }, + }, // lambda to handle press state bg color for enrichedText ) { val spans = text.getSpans(0, text.length, EnrichedMentionSpan::class.java) for (span in spans) { @@ -35,7 +35,6 @@ object MentionBackgroundDrawer { val start = text.getSpanStart(span) val end = text.getSpanEnd(span) - if (start < 0 || end <= start) continue paint.color = color drawSpanBackground(canvas, layout, start, end, mentionStyle.borderRadius) @@ -71,18 +70,20 @@ object MentionBackgroundDrawer { segmentEnd, layout.getLineBottom(line).toFloat(), ) - if (rect.width() <= 0f) continue // Only round the outer ends of a wrapped mention. val leftRadius = if (isFirst) radius else 0f val rightRadius = if (isLast) radius else 0f - // Corner order: top-left, top-right, bottom-right, bottom-left + // top-left radii[0] = leftRadius radii[1] = leftRadius + // top-right radii[2] = rightRadius radii[3] = rightRadius + // bottom-right radii[4] = rightRadius radii[5] = rightRadius + // bottom-left radii[6] = leftRadius radii[7] = leftRadius diff --git a/apps/example-web/src/defaultHtmlStyle.ts b/apps/example-web/src/defaultHtmlStyle.ts index 10f10c0cc..6ef15ec7c 100644 --- a/apps/example-web/src/defaultHtmlStyle.ts +++ b/apps/example-web/src/defaultHtmlStyle.ts @@ -68,6 +68,7 @@ export const WEB_DEFAULT_HTML_STYLE: HtmlStyle = { backgroundColor: 'lightgreen', color: 'green', textDecorationLine: 'none', + borderRadius: 0, }, '#': { backgroundColor: 'lightblue', diff --git a/apps/example/src/constants/editorConfig.ts b/apps/example/src/constants/editorConfig.ts index 3d6f6f48e..f3b20aacf 100644 --- a/apps/example/src/constants/editorConfig.ts +++ b/apps/example/src/constants/editorConfig.ts @@ -113,7 +113,7 @@ export const htmlStyle = { color: 'green', backgroundColor: 'lightgreen', textDecorationLine: 'none', - borderRadius: 14, + borderRadius: 0, }, }, ol: { diff --git a/apps/example/src/constants/htmlStyle.ts b/apps/example/src/constants/htmlStyle.ts index 564ec8533..2d10e3a88 100644 --- a/apps/example/src/constants/htmlStyle.ts +++ b/apps/example/src/constants/htmlStyle.ts @@ -57,7 +57,7 @@ export const htmlStyle = { color: 'green', backgroundColor: 'lightgreen', textDecorationLine: 'none', - borderRadius: 14, + borderRadius: 0, }, }, ol: { From 30bc1b2216433fca18ac694468c3899dcd9e71b2 Mon Sep 17 00:00:00 2001 From: relextm19 Date: Thu, 5 Nov 2026 12:16:21 +0100 Subject: [PATCH 09/18] refactor(ios): collect mentions based on MentionsParam not bgColor --- ios/extensions/LayoutManagerExtension.mm | 29 ++++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/ios/extensions/LayoutManagerExtension.mm b/ios/extensions/LayoutManagerExtension.mm index c59da7a14..1e7a25fb3 100644 --- a/ios/extensions/LayoutManagerExtension.mm +++ b/ios/extensions/LayoutManagerExtension.mm @@ -70,31 +70,40 @@ - (void)drawMentionBackgrounds:(id)host origin:(CGPoint)origin visibleCharRange:(NSRange)visibleCharRange { NSTextStorage *textStorage = host.textView.textStorage; + NSRange wholeText = NSMakeRange(0, textStorage.length); NSMutableArray *ranges = [[NSMutableArray alloc] init]; - [textStorage enumerateAttribute:MentionRoundedBackgroundAttributeName + [textStorage enumerateAttribute:@"EnrichedMention" inRange:visibleCharRange options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL *_Nonnull stop) { - if (value != nullptr && range.length > 0) { - [ranges addObject:[NSValue valueWithRange:range]]; + if (value == nullptr || range.length == 0) { + return; } + NSRange fullRange; + [textStorage attribute:@"EnrichedMention" + atIndex:range.location + longestEffectiveRange:&fullRange + inRange:wholeText]; + [ranges addObject:[NSValue valueWithRange:fullRange]]; }]; for (NSValue *rangeValue in ranges) { NSRange range = [rangeValue rangeValue]; + UIColor *bgColor = + [textStorage attribute:MentionRoundedBackgroundAttributeName + atIndex:range.location + effectiveRange:nullptr]; + // mentions without a border radius are drawn natively via + // NSBackgroundColorAttributeName + if (bgColor == nullptr) { + continue; + } MentionParams *params = [textStorage attribute:@"EnrichedMention" atIndex:range.location effectiveRange:nullptr]; - if (params == nullptr) { - continue; - } MentionStyleProps *props = [host.config mentionStylePropsForIndicator:params.indicator]; - UIColor *bgColor = - [textStorage attribute:MentionRoundedBackgroundAttributeName - atIndex:range.location - effectiveRange:nullptr]; UIFont *font = [textStorage attribute:NSFontAttributeName atIndex:range.location effectiveRange:nullptr]; From 7a13dc68069ccef8c04d0a8bd497b834005083ef Mon Sep 17 00:00:00 2001 From: relextm19 Date: Thu, 5 Nov 2026 12:21:25 +0100 Subject: [PATCH 10/18] fix(android): lint fix --- .../common/MentionBackgroundDrawer.kt | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt b/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt index d13610400..a5945964e 100644 --- a/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt +++ b/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt @@ -19,13 +19,13 @@ object MentionBackgroundDrawer { // Must be called with the canvas translated to the layout origin, before the text is drawn. fun draw( - canvas: Canvas, - layout: Layout, - text: Spanned, - style: EnrichedStyle, - backgroundColorFor: (EnrichedMentionSpan, MentionStyle) -> Int = { _, mentionStyle -> - mentionStyle.backgroundColor - }, // lambda to handle press state bg color for enrichedText + canvas: Canvas, + layout: Layout, + text: Spanned, + style: EnrichedStyle, + backgroundColorFor: (EnrichedMentionSpan, MentionStyle) -> Int = { _, mentionStyle -> + mentionStyle.backgroundColor + }, // lambda to handle press state bg color for enrichedText ) { val spans = text.getSpans(0, text.length, EnrichedMentionSpan::class.java) for (span in spans) { @@ -42,11 +42,11 @@ object MentionBackgroundDrawer { } private fun drawSpanBackground( - canvas: Canvas, - layout: Layout, - start: Int, - end: Int, - radius: Float, + canvas: Canvas, + layout: Layout, + start: Int, + end: Int, + radius: Float, ) { val firstLine = layout.getLineForOffset(start) val lastLine = layout.getLineForOffset(end - 1) @@ -56,19 +56,19 @@ object MentionBackgroundDrawer { val isLast = line == lastLine val segmentStart = - if (isFirst) layout.getPrimaryHorizontal(start) else layout.getLineLeft(line) + if (isFirst) layout.getPrimaryHorizontal(start) else layout.getLineLeft(line) val segmentEnd = - if (isLast) { - layout.getPrimaryHorizontal(end) - } else { - layout.getLineRight(line) - } + if (isLast) { + layout.getPrimaryHorizontal(end) + } else { + layout.getLineRight(line) + } rect.set( - segmentStart, - layout.getLineTop(line).toFloat(), - segmentEnd, - layout.getLineBottom(line).toFloat(), + segmentStart, + layout.getLineTop(line).toFloat(), + segmentEnd, + layout.getLineBottom(line).toFloat(), ) // Only round the outer ends of a wrapped mention. From c22155d3ca280ec3fc3700d856e17c8d8ad9e391 Mon Sep 17 00:00:00 2001 From: relextm19 Date: Fri, 6 Nov 2026 13:47:56 +0100 Subject: [PATCH 11/18] refactor(ios): only use the layout menager to draw mention backgrounds --- ios/extensions/LayoutManagerExtension.mm | 16 +++++++++------- ios/interfaces/MentionStyleProps.h | 6 +++--- ios/interfaces/MentionStyleProps.mm | 3 +-- ios/styles/MentionStyle.mm | 9 +++------ ios/utils/EnrichedTextTouchHandler.mm | 7 ++----- 5 files changed, 18 insertions(+), 23 deletions(-) diff --git a/ios/extensions/LayoutManagerExtension.mm b/ios/extensions/LayoutManagerExtension.mm index 1e7a25fb3..3617999e9 100644 --- a/ios/extensions/LayoutManagerExtension.mm +++ b/ios/extensions/LayoutManagerExtension.mm @@ -90,13 +90,10 @@ - (void)drawMentionBackgrounds:(id)host for (NSValue *rangeValue in ranges) { NSRange range = [rangeValue rangeValue]; - UIColor *bgColor = - [textStorage attribute:MentionRoundedBackgroundAttributeName - atIndex:range.location - effectiveRange:nullptr]; - // mentions without a border radius are drawn natively via - // NSBackgroundColorAttributeName - if (bgColor == nullptr) { + UIColor *bgColor = [textStorage attribute:MentionBackgroundAttributeName + atIndex:range.location + effectiveRange:nullptr]; + if (bgColor == nullptr || CGColorGetAlpha(bgColor.CGColor) == 0) { continue; } MentionParams *params = [textStorage attribute:@"EnrichedMention" @@ -130,6 +127,11 @@ - (void)drawMentionBackgrounds:(id)host bgRect.origin.x += origin.x; bgRect.origin.y += origin.y; + if (props.borderRadius <= 0) { + [[UIBezierPath bezierPathWithRect:bgRect] fill]; + continue; + } + UIRectCorner corners = 0; if (i == 0) { corners = UIRectCornerTopLeft | UIRectCornerBottomLeft; diff --git a/ios/interfaces/MentionStyleProps.h b/ios/interfaces/MentionStyleProps.h index d8d166c58..0f2f10672 100644 --- a/ios/interfaces/MentionStyleProps.h +++ b/ios/interfaces/MentionStyleProps.h @@ -4,9 +4,9 @@ #import #import -// holds the mention's background color when it should be drawn with rounded -// corners by the layout manager instead of NSBackgroundColorAttributeName -extern NSString *const MentionRoundedBackgroundAttributeName; +// holds the mention's background color, drawn by the layout manager instead of +// NSBackgroundColorAttributeName so the corners can be rounded +extern NSString *const MentionBackgroundAttributeName; @interface MentionStyleProps : NSObject @property UIColor *color; diff --git a/ios/interfaces/MentionStyleProps.mm b/ios/interfaces/MentionStyleProps.mm index 3855922c2..4c843d983 100644 --- a/ios/interfaces/MentionStyleProps.mm +++ b/ios/interfaces/MentionStyleProps.mm @@ -2,8 +2,7 @@ #import "extensions/StringExtension.h" #import -NSString *const MentionRoundedBackgroundAttributeName = - @"EnrichedMentionRoundedBackground"; +NSString *const MentionBackgroundAttributeName = @"EnrichedMentionBackground"; @implementation MentionStyleProps diff --git a/ios/styles/MentionStyle.mm b/ios/styles/MentionStyle.mm index ac37c8b5a..089ca2dcc 100644 --- a/ios/styles/MentionStyle.mm +++ b/ios/styles/MentionStyle.mm @@ -55,14 +55,11 @@ - (void)applyStyling:(NSRange)range { NSForegroundColorAttributeName : styleProps.color, NSUnderlineColorAttributeName : styleProps.color, NSStrikethroughColorAttributeName : styleProps.color, + // backgrounds are drawn by the layout manager + MentionBackgroundAttributeName : + [styleProps.backgroundColor colorWithResolvedAlpha], } mutableCopy]; - // rounded backgrounds are drawn by the layout manager - NSAttributedStringKey bgKey = styleProps.borderRadius > 0 - ? MentionRoundedBackgroundAttributeName - : NSBackgroundColorAttributeName; - newAttrs[bgKey] = [styleProps.backgroundColor colorWithResolvedAlpha]; - if (styleProps.decorationLine == DecorationUnderline) { newAttrs[NSUnderlineStyleAttributeName] = @(NSUnderlineStyleSingle); } diff --git a/ios/utils/EnrichedTextTouchHandler.mm b/ios/utils/EnrichedTextTouchHandler.mm index c83cc26c2..292d04149 100644 --- a/ios/utils/EnrichedTextTouchHandler.mm +++ b/ios/utils/EnrichedTextTouchHandler.mm @@ -103,7 +103,6 @@ - (void)updateVisualsPressed:(BOOL)pressed { if (pressed) { UIColor *color = nil; UIColor *bgColor = nil; - NSAttributedStringKey bgKey = NSBackgroundColorAttributeName; if ([_activeAttrKey isEqualToString:@"EnrichedMention"]) { MentionParams *m = (MentionParams *)_activeValue; @@ -111,9 +110,6 @@ - (void)updateVisualsPressed:(BOOL)pressed { [self.view.config mentionStylePropsForIndicator:m.indicator]; color = [mProps pressColor]; bgColor = [mProps pressBackgroundColor]; - if (mProps.borderRadius > 0) { - bgKey = MentionRoundedBackgroundAttributeName; - } } else { color = [self.view.config linkPressColor]; } @@ -125,7 +121,8 @@ - (void)updateVisualsPressed:(BOOL)pressed { newAttrs[NSStrikethroughColorAttributeName] = color; } if (bgColor) { - newAttrs[bgKey] = [bgColor colorWithResolvedAlpha]; + newAttrs[MentionBackgroundAttributeName] = + [bgColor colorWithResolvedAlpha]; } [self.view.textView.textStorage addAttributes:newAttrs range:_activeRange]; From 0b8f7ec316d8e11f447f16a1e2b81b0ed342a45d Mon Sep 17 00:00:00 2001 From: relextm19 Date: Mon, 9 Nov 2026 13:32:53 +0100 Subject: [PATCH 12/18] refactor(ios): move the style key declaration --- ios/interfaces/MentionStyleProps.h | 4 ---- ios/interfaces/MentionStyleProps.mm | 2 -- ios/interfaces/StyleHeaders.h | 4 ++++ ios/styles/MentionStyle.mm | 1 + ios/utils/EnrichedTextTouchHandler.mm | 1 + 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ios/interfaces/MentionStyleProps.h b/ios/interfaces/MentionStyleProps.h index 0f2f10672..a1cd6aaba 100644 --- a/ios/interfaces/MentionStyleProps.h +++ b/ios/interfaces/MentionStyleProps.h @@ -4,10 +4,6 @@ #import #import -// holds the mention's background color, drawn by the layout manager instead of -// NSBackgroundColorAttributeName so the corners can be rounded -extern NSString *const MentionBackgroundAttributeName; - @interface MentionStyleProps : NSObject @property UIColor *color; @property UIColor *backgroundColor; diff --git a/ios/interfaces/MentionStyleProps.mm b/ios/interfaces/MentionStyleProps.mm index 4c843d983..aa7012228 100644 --- a/ios/interfaces/MentionStyleProps.mm +++ b/ios/interfaces/MentionStyleProps.mm @@ -2,8 +2,6 @@ #import "extensions/StringExtension.h" #import -NSString *const MentionBackgroundAttributeName = @"EnrichedMentionBackground"; - @implementation MentionStyleProps + (MentionStyleProps *)getSingleMentionStylePropsFromFollyDynamic: diff --git a/ios/interfaces/StyleHeaders.h b/ios/interfaces/StyleHeaders.h index c664429f0..0b427bb8b 100644 --- a/ios/interfaces/StyleHeaders.h +++ b/ios/interfaces/StyleHeaders.h @@ -45,6 +45,10 @@ config:(EnrichedConfig *)config; @end +// holds the mention's background color, drawn by the layout manager instead of +// NSBackgroundColorAttributeName so the corners can be rounded +extern NSString *const MentionBackgroundAttributeName; + @interface MentionStyle : StyleBase - (void)addMention:(NSString *)indicator text:(NSString *)text diff --git a/ios/styles/MentionStyle.mm b/ios/styles/MentionStyle.mm index 089ca2dcc..b3beed9aa 100644 --- a/ios/styles/MentionStyle.mm +++ b/ios/styles/MentionStyle.mm @@ -8,6 +8,7 @@ // custom NSAttributedStringKey to differentiate from links static NSString *const MentionAttributeName = @"EnrichedMention"; +NSString *const MentionBackgroundAttributeName = @"EnrichedMentionBackground"; @implementation MentionStyle { NSValue *_activeMentionRange; diff --git a/ios/utils/EnrichedTextTouchHandler.mm b/ios/utils/EnrichedTextTouchHandler.mm index 292d04149..975e26ff4 100644 --- a/ios/utils/EnrichedTextTouchHandler.mm +++ b/ios/utils/EnrichedTextTouchHandler.mm @@ -6,6 +6,7 @@ #import "interfaces/MentionParams.h" #import "interfaces/MentionStyleProps.h" #import "interfaces/StyleBase.h" +#import "interfaces/StyleHeaders.h" @implementation EnrichedTextTouchHandler { NSRange _activeRange; From a7aca8f98616a9118c46fda97da7e3bbbd4b11dd Mon Sep 17 00:00:00 2001 From: relextm19 Date: Mon, 9 Nov 2026 13:44:05 +0100 Subject: [PATCH 13/18] fix(ios): dont draw mention background over newline --- apps/example/ios/Podfile.lock | 162 +++++++++++------------ ios/extensions/LayoutManagerExtension.mm | 65 +++++++-- 2 files changed, 135 insertions(+), 92 deletions(-) diff --git a/apps/example/ios/Podfile.lock b/apps/example/ios/Podfile.lock index cbcb748e6..e7a4e4435 100644 --- a/apps/example/ios/Podfile.lock +++ b/apps/example/ios/Podfile.lock @@ -2063,95 +2063,95 @@ EXTERNAL SOURCES: :path: build/rncore-facades/Yoga SPEC CHECKSUMS: - boost: 2a9d6e1d9873337543f08d9dbc007b288f4e113b - DoubleConversion: e85e4faac763226bfd1cc4c6a98d8355149b27a5 - fast_float: 908e5ee35999f3d91af4b962ac951acac591866c - FBLazyVector: 953381a667ad5f4119b929026e53c4f3aa0da7e7 - fmt: c7776a2a4b1d7ce88b809a1e4d1f7add0f2369df - glog: b4427c3119645da795ff09985ba9da909c940c96 + boost: 8502bfdc46e2804408af2e163049ece181009af4 + DoubleConversion: 501a575c40c0b50c89685762dd3e415e6bb26fb0 + fast_float: 7c925d1cebf8328d4018d061f49377e9f887e3b4 + FBLazyVector: fdebac2dfe9c53bca49f8218fbdf1e24e36c8be0 + fmt: ba0886e864ebb21d14c98b2e12e164b8002f5b93 + glog: 3cf7cb46f743c4bc758ae3e6d9c15bd1b4cfd6d4 hermes-engine: a1158910bb7e300b9e3d2f1e2d433f817ec1a4b5 - RCT-Folly: d173e541eeb78cad5c81011c1bbf62d5b86b9778 - RCTDeprecation: b5015bad0dc536eff092b252e8cdcf7903448e03 - RCTRequired: 1f568a6519677ef482387250f5a098a9ec5dba57 + RCT-Folly: 82921e585c0400eda46fac1068297aa9dfb035e4 + RCTDeprecation: e134f2a2c096a6450f5fcbbe949531f913a2ff04 + RCTRequired: f1a68295837ee8f91e112ed1b5694d12e7ff1784 RCTSwiftUI: 4b21ec5b1f86acb9c96bb429100ad88d4023ed76 - RCTSwiftUIWrapper: 118a21dd01e8000e0583f5f5660a815975aa9cf5 + RCTSwiftUIWrapper: 68bd9fac4e710259cb2b202472adc5f4d113e872 RCTTypeSafety: 77078a9c26030dd84a6bdae74ed900159f89a098 React: 8dafd0ef058191e9e7238cfa6b3deaa24398e5dd - React-bridging: af8fb3f4aebda43f116b69d08384bc3058940b24 - React-callinvoker: 990aad7c20625b59200be77eea7f21f80280a9db - React-Core: f9dd5e5a1c462c8bed235c305c2e2309dfc105f8 - React-Core-prebuilt: 9e4e8e87cae574b60a941e4ce6b621911e4d5cf3 - React-CoreModules: fe68e8743f1586a0557fe8d754b34c0c8d8c5b74 - React-cxxreact: 4a05b5c0a8d75d56816529edbc02beab1606e216 + React-bridging: 658efeb1b4704d5f60ea2fb6e8ca826ab0ae3234 + React-callinvoker: 4e40c208c1ea46686c084a7c23da6a65cbb99482 + React-Core: a831be15fcea0e345a24cb10d6cc0b87e9913d03 + React-Core-prebuilt: 0fd2555a42f40e7770ced1c7dfc5ee1dbfe041cd + React-CoreModules: a86fbe698fd817c17b3936832dc1106a130c4694 + React-cxxreact: 48ca56bd4f26de869478a803a5544b101a57cde6 React-cxxstableapi: f35502b4c542a0d44031b42f91c4ca813d267e16 - React-debug: 225d5d56d096312e1a744b6839a2ad929258b2dd - React-defaultsnativemodule: e88fa0070d99850f11ca368be23f5bd960f9dcdc - React-domnativemodule: 45f2a0aac0866d0da969125eb0c67cecea189180 - React-Fabric: 15c7c42e5faef29d76e398824556f7cf9cc04d35 - React-FabricComponents: 3025339f15ac4715de8a2619a3146c842035bd26 - React-FabricImage: cc00f781af90a934f35c1050466b18fddd86d4cd - React-featureflags: 548879104928d75f937bdea454ce0cb89673878a - React-featureflagsnativemodule: 30eed289f12d51ba7a9744545d783fcfc76b71fd - React-graphics: 69c2173051f1cfa5daf370d5e2c2e1783a621129 - React-hermes: 42d3b1d6de9857595c256eb8996bb106ed40e0ed - React-idlecallbacksnativemodule: 6cc2ba62bb034708f6dd90e61a65a1eb7d3e3bcf - React-ImageManager: 2cdaadea57d74052a6548155e157e6b10e813bd2 - React-intersectionobservernativemodule: 0bcd8856f0eabff39b8f3ba0203b87b0d1d3fca2 - React-jserrorhandler: f10ca6b509737a3f872eb6aafe97fd4394ce33d9 - React-jsi: f85e93f9b8d40804731d90b49165b2a9dd842d81 - React-jsiexecutor: 46ef706cd6a6078ded3338b45bb954e7895505bc - React-jsinspector: 378fea230352b1c00d497283b24df340743627cd - React-jsinspectorcdp: b48d8a2931f505fb71213facf4668db6b0d714e3 - React-jsinspectornetwork: 24f58d9def362e363b3aa7d3f65f1bbdd340396b - React-jsinspectortracing: 31f12c0953ecf1bc98872398cb15e6907cc89aa7 - React-jsitooling: b81a8421cd105cfa04d5575192dee261f719c243 - React-jsitracing: d502415ab958446c09c164a0378d62a61be2b438 - React-logger: 08a3fb49d43447115f6a094cbbe4aaba308d4ed0 - React-Mapbuffer: ebfc6ddeba62b89b3118ab9206e83b8ad1419123 - React-microtasksnativemodule: b8478c203a5d65f5729a5d72564b5625306246d2 - React-mutationobservernativemodule: 4b42b9a136d149799864720e5201a9ce190d2bef - react-native-image-picker: f166d85a3fbdc52ac9ed01062250140c44ba247b - React-NativeModulesApple: cb7ad2bcca44bc4e65eff580b7a7c2d2c6914fa0 - React-networking: 71c78b3c3afca071b8534b10ee501177b7938c9b - React-oscompat: 15c32b3f1e17618e60658411167c2746857fbba5 - React-perflogger: 7997b8eaa3d953be049f3897f9796a1c1eaefdc7 - React-performancecdpmetrics: 1f1cb4196ce97621504a11cd1a106fcd76660b6f - React-performancetimeline: 60f947e3384c00396e71bbb9548e112a94eb13a8 + React-debug: 238e15d17dfded9419a6d739d4c8b60968bad02e + React-defaultsnativemodule: c028edc7e48914344b823931aec1cc4ffabe631e + React-domnativemodule: b09770fc69f5ce5759de98f8065cab900b6d87d6 + React-Fabric: a157c978603fa2796f349f3a27d17861e55804c5 + React-FabricComponents: c7c58a1deea5db215e9d5a2aec890e208d5d5075 + React-FabricImage: 234346bf5a3ef918f3873e845b57b93b2b1f31c0 + React-featureflags: a00ac5c38e63d5f86de895ca923f07f5ff76de66 + React-featureflagsnativemodule: 6b93ba0aef46757b9d54166475abc5e4fa80e70d + React-graphics: 634bc2e5884b4a29f56aa8aef719e03171a23f6b + React-hermes: 9ce7aaf6784709e196ac51bfd89dd6c551e3fb4c + React-idlecallbacksnativemodule: e02e194086278377ced48b7fd7816b6c925b9e7e + React-ImageManager: 452d4b3587f21d3384868e2abaab7c0a952b1d1c + React-intersectionobservernativemodule: 3ddbc206bc95c086f1df6eea04aa617ae02627d2 + React-jserrorhandler: a0d842e1f74cc10e597fde2a6447860483df2b13 + React-jsi: 489de0620905b88a17ccb0ac2328046af43e7ebd + React-jsiexecutor: f0e2ae6d98b587d3505ebde246599ee3ad97cee1 + React-jsinspector: 515bf11caeda5df444f39aec63e377ef77ad7696 + React-jsinspectorcdp: be9ac71a77880a6fcc95375e7e61a79e152a3203 + React-jsinspectornetwork: a4bc1475897a2301d114d7a8605af3e8760f9e52 + React-jsinspectortracing: 7d35952c944dc337d1a4167605c1338108880219 + React-jsitooling: 1886dc5058e9feded2136b0d9ba5c189c6af5faa + React-jsitracing: 76b58feee3fb0539c8967e5b9de1a40ad8014f09 + React-logger: 3d2b406a780fed50ad0bbd07452b373c2a515308 + React-Mapbuffer: a2dae4f2cb335ebb97f2240494d0c2bab84cd339 + React-microtasksnativemodule: 8b3aaa5f3b907ecf071b105589868d9f027a448d + React-mutationobservernativemodule: 11d77d3f7360578f07847843544ada23cc473049 + react-native-image-picker: dc809b800c612d43b6508095cca505c32cf9d3c8 + React-NativeModulesApple: 52f3def085f129de1307e3eb78e26729ff70f421 + React-networking: 1e6441349ac72bfd4f7a79c300c3dd76993a7058 + React-oscompat: e64123dd8199f9e99cede19fa542c3da3445481e + React-perflogger: f1466e0f46ce706aef73a559337eca85f51a40b7 + React-performancecdpmetrics: f238752e99eb7c69c782020827bff38a4b1b2ef2 + React-performancetimeline: f1b216fa02200c859cd18ef345d4230cd712137a React-RCTActionSheet: 81662769b1f576e9c2e074deb41d6b83d1c7e29f - React-RCTAnimatedModuleProvider: e71da181d50d3d19ab5fa24ace7b9cef67453ba2 - React-RCTAnimation: d900133c5fd04ea66576c0221e369be255aa27c8 - React-RCTAppDelegate: 8190863c58350373cc2929ef8b22faeaeaa3fa5f - React-RCTBlob: 7d6a4709dcd74281b6d0e8ccd10e2847f3c882fb - React-RCTFabric: 9a34936cb16f86e90fc4e5911ca068c43db78c0f - React-RCTFBReactNativeSpec: d9f8c284e5d965bd7a2a718e06b076204c383394 - React-RCTImage: 5d62b5686350935a52e0bc5c961339476a0da0d9 - React-RCTLinking: 5a019526644083957085610a3399094fd8d0819e - React-RCTNetwork: a7b8711829339321eb368aa1708f35b55a9e5e82 - React-RCTRuntime: a745878bbad8ba81420e95030b317c2116a3ae33 - React-RCTSettings: 9ac026a882b58f12c8ddaff02df4e60988439310 - React-RCTText: f9bf7738a96fc25968857f4c1c4d5c4257874b41 - React-RCTVibration: 400e227a70dfdf7c0924cd990c54c57fbcb194d1 + React-RCTAnimatedModuleProvider: a9829773197f782c19ad86c5438a2cc199203774 + React-RCTAnimation: ad9dd2c6c3b4d07e583c2b79354858c4f34481a0 + React-RCTAppDelegate: 70398a06e10ada27cdf77dc2b43f883126a91ac0 + React-RCTBlob: f3d86b491b8f28c36ced0cb750878b62f72e1380 + React-RCTFabric: 3767f97183c40ba3dadf007b17a01be2cd4e632a + React-RCTFBReactNativeSpec: d7ad5d9edc1865f38b9aac5b7091c3abb6978eed + React-RCTImage: 46ad408f777dce991d4095d7e73a568212be6baa + React-RCTLinking: 547427cc885bfa74b3cbba405971c5270defde7a + React-RCTNetwork: 52c00c0fe07327df9b9fe9881b4f5550dc5ced37 + React-RCTRuntime: 081fd457d305c3aee76c335c568e693ed107f48e + React-RCTSettings: 9cd0b2be41404574ec280b6b8e73c2208c842050 + React-RCTText: 5a6d38456eabc0a1a7c0d47d592390d35c6de57c + React-RCTVibration: c1815b4f471462954a4b7d8835155e053cec5412 React-rendererconsistency: b7996da82c8d3f4a7928b39be3e437b72ad92012 - React-renderercss: 3b11f40c0c21140902dee115e8fefcf59f75c703 - React-rendererdebug: 331a5c2ebf9294b82eb3531e0e1efbaa0537a0bb - React-resizeobservernativemodule: 24a21a6d00e9dd360f4ef8bf4065040a8b5bc985 - React-RuntimeApple: 0aaf9964151b80c9efc8fd08a80e96ec9c7d60dd - React-RuntimeCore: df973653596b10d77a497c2c34a9f8325c307249 - React-runtimeexecutor: 5c613fede1667a12a38cfc566ff3026bfde3b5f7 - React-RuntimeHermes: d7bcefa9b395d1646c906c4112a1f8de7212e90b - React-runtimescheduler: 431db4de0f22bb2b3315cb728ac8983a566c955a - React-timing: 1d927443f5c37bb25dee28478ef1f20f05996626 - React-utils: d50a630c236f386a9ac019f360faf661e5c4717e - React-viewtransitionnativemodule: 8b0ce65faa32cdfc14aaa89680711cca3321c180 - React-webperformancenativemodule: 087b85db47f4e83dd719a03822986b6c2f073335 - ReactAppDependencyProvider: 1666a962dbb4b36824b6297f5fc83049dd7c3717 - ReactCodegen: 5b3cdb1f612a81f3b543a94f425ecd8518c32f2c - ReactCommon: c6895b36d81986f89a7e40a00b4b72ca70e82710 + React-renderercss: 4c256900eba87661178771766da0171493f88848 + React-rendererdebug: 4d9df8cf2cac6eee7002a4d14358c79fdf6ad8c5 + React-resizeobservernativemodule: 750d334554e7c44bacf14568a8a0d0048cc4c278 + React-RuntimeApple: 2045a6206895ad5ce90d141d1bd384888fd06c42 + React-RuntimeCore: b051facffbc7ca038097278cabf810d6d86dd328 + React-runtimeexecutor: b06ec9bb745a97cbd3ce25e3e02be7b8058fb374 + React-RuntimeHermes: fcfa8baca49a6d37d331147568d51d5b8b0a175d + React-runtimescheduler: c2afe74d1db006bafd9270186101f5378b1bef81 + React-timing: 6a1a8cfb0caae8de243aba16fa92fa81de23efaf + React-utils: 2384e5db98378df8c0bf2c0d5489ec1b8e80b398 + React-viewtransitionnativemodule: 8505b253586f792c6c722869a664889797ecae3e + React-webperformancenativemodule: 67f32fde92ed7e8470ee1c669bdb7c2fcb760141 + ReactAppDependencyProvider: 782ee9546c9cd3b53b73f1e9e3dd728540085fc7 + ReactCodegen: 7b71f4464442e9b6eae41094d11076d56c51c0e3 + ReactCommon: 145a14b942b19fc2fe38927f261955ada56978aa ReactNativeDependencies: d3b7423ba1e52525e42085c8470109abde583d2e - ReactNativeEnrichedHtml: 0575ded0afcd0b6b242d24011b8761925f4a0767 - SocketRocket: d57b1af80c029e12a75cd9b218287c67381e4593 - Yoga: 58b502c52b14ad3c4468805d461fc37d275c2a42 + ReactNativeEnrichedHtml: a90b3959b4ec18a1001a47d6c63fd567aeedf7d4 + SocketRocket: 37aec555668fb852ec12e3c0de59a86ca58f0871 + Yoga: d1c536142c5ff8ec8cd856ab2a7c227a1d875c8e PODFILE CHECKSUM: 17de42bc1248ff5392a5a74f9edf4660b05a1695 -COCOAPODS: 1.15.2 +COCOAPODS: 1.17.0 diff --git a/ios/extensions/LayoutManagerExtension.mm b/ios/extensions/LayoutManagerExtension.mm index 3617999e9..8c5a2fb53 100644 --- a/ios/extensions/LayoutManagerExtension.mm +++ b/ios/extensions/LayoutManagerExtension.mm @@ -106,18 +106,43 @@ - (void)drawMentionBackgrounds:(id)host effectiveRange:nullptr]; [bgColor setFill]; - NSRange glyphRange = [self glyphRangeForCharacterRange:range - actualCharacterRange:nullptr]; - // one rect per line in case the mention wraps NSMutableArray *lineRects = [[NSMutableArray alloc] init]; - [self enumerateEnclosingRectsForGlyphRange:glyphRange - withinSelectedGlyphRange:NSMakeRange(NSNotFound, 0) - inTextContainer:host.textView.textContainer - usingBlock:^(CGRect rect, BOOL *stop) { - [lineRects - addObject:[NSValue - valueWithCGRect:rect]]; - }]; + NSArray *nonNewlineRanges = [RangeUtils getNonNewlineRangesIn:host.textView + range:range]; + for (NSValue *subRangeValue in nonNewlineRanges) { + NSRange glyphRange = + [self glyphRangeForCharacterRange:[subRangeValue rangeValue] + actualCharacterRange:nullptr]; + [self + enumerateLineFragmentsForGlyphRange:glyphRange + usingBlock:^(CGRect rect, CGRect usedRect, + NSTextContainer *container, + NSRange lineGlyphRange, + BOOL *stop) { + NSRange lineRange = NSIntersectionRange( + lineGlyphRange, glyphRange); + // trailing whitespace at a soft wrap + // would get a background with nothing + // after it, so trim it off + if (NSMaxRange(lineRange) < + NSMaxRange(glyphRange)) { + lineRange = [self + trimTrailingWhitespaceFromGlyphRange: + lineRange + textStorage: + textStorage]; + } + if (lineRange.length == 0) { + return; + } + CGRect lineRect = [self + boundingRectForGlyphRange:lineRange + inTextContainer:container]; + [lineRects + addObject:[NSValue valueWithCGRect: + lineRect]]; + }]; + } // only the mention's start and end get rounded, so a wrapped mention // still has 4 rounded corners in total @@ -474,6 +499,24 @@ - (NSString *)getDecimalMarkerForList:(id)host return [NSString stringWithFormat:@"%ld.", (long)(itemNumber)]; } +// Drops whitespace glyphs from the end of a glyph range, used so a mention +// background that wraps doesn't extend past its last visible character. +- (NSRange)trimTrailingWhitespaceFromGlyphRange:(NSRange)glyphRange + textStorage:(NSTextStorage *)textStorage { + NSCharacterSet *whitespace = [NSCharacterSet whitespaceCharacterSet]; + while (glyphRange.length > 0) { + NSUInteger charIndex = + [self characterIndexForGlyphAtIndex:NSMaxRange(glyphRange) - 1]; + if (charIndex >= textStorage.length || + ![whitespace characterIsMember:[textStorage.string + characterAtIndex:charIndex]]) { + break; + } + glyphRange.length--; + } + return glyphRange; +} + // Returns a usedRect adjusted to cover only the text portion of the line. // When minimumLineHeight expands the line box, extra space is added at the top // and text stays at the bottom. This strips that padding so markers align with From 6e967e89336fb6dd14fd645cb60dbd728b832b88 Mon Sep 17 00:00:00 2001 From: relextm19 Date: Mon, 9 Nov 2026 14:18:21 +0100 Subject: [PATCH 14/18] refactor(ios): change the way bgKey is defined --- ios/extensions/LayoutManagerExtension.mm | 7 ++++--- ios/interfaces/StyleHeaders.h | 5 +---- ios/styles/MentionStyle.mm | 9 ++++++++- ios/utils/EnrichedTextTouchHandler.mm | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/ios/extensions/LayoutManagerExtension.mm b/ios/extensions/LayoutManagerExtension.mm index 8c5a2fb53..a11b82d84 100644 --- a/ios/extensions/LayoutManagerExtension.mm +++ b/ios/extensions/LayoutManagerExtension.mm @@ -90,9 +90,10 @@ - (void)drawMentionBackgrounds:(id)host for (NSValue *rangeValue in ranges) { NSRange range = [rangeValue rangeValue]; - UIColor *bgColor = [textStorage attribute:MentionBackgroundAttributeName - atIndex:range.location - effectiveRange:nullptr]; + UIColor *bgColor = + [textStorage attribute:[MentionStyle getBackgroundAttributeName] + atIndex:range.location + effectiveRange:nullptr]; if (bgColor == nullptr || CGColorGetAlpha(bgColor.CGColor) == 0) { continue; } diff --git a/ios/interfaces/StyleHeaders.h b/ios/interfaces/StyleHeaders.h index 0b427bb8b..1ee66177e 100644 --- a/ios/interfaces/StyleHeaders.h +++ b/ios/interfaces/StyleHeaders.h @@ -45,11 +45,8 @@ config:(EnrichedConfig *)config; @end -// holds the mention's background color, drawn by the layout manager instead of -// NSBackgroundColorAttributeName so the corners can be rounded -extern NSString *const MentionBackgroundAttributeName; - @interface MentionStyle : StyleBase ++ (NSString *)getBackgroundAttributeName; - (void)addMention:(NSString *)indicator text:(NSString *)text attributes:(NSString *)attributes; diff --git a/ios/styles/MentionStyle.mm b/ios/styles/MentionStyle.mm index b3beed9aa..51f3e9173 100644 --- a/ios/styles/MentionStyle.mm +++ b/ios/styles/MentionStyle.mm @@ -8,7 +8,10 @@ // custom NSAttributedStringKey to differentiate from links static NSString *const MentionAttributeName = @"EnrichedMention"; -NSString *const MentionBackgroundAttributeName = @"EnrichedMentionBackground"; +// holds the mention's background color, drawn by the layout manager instead of +// NSBackgroundColorAttributeName so the corners can be rounded +static NSString *const MentionBackgroundAttributeName = + @"EnrichedMentionBackground"; @implementation MentionStyle { NSValue *_activeMentionRange; @@ -18,6 +21,10 @@ @implementation MentionStyle { NSString *_lastEmittedMentionText; } ++ (NSString *)getBackgroundAttributeName { + return MentionBackgroundAttributeName; +} + + (StyleType)getType { return Mention; } diff --git a/ios/utils/EnrichedTextTouchHandler.mm b/ios/utils/EnrichedTextTouchHandler.mm index 975e26ff4..e5352bd97 100644 --- a/ios/utils/EnrichedTextTouchHandler.mm +++ b/ios/utils/EnrichedTextTouchHandler.mm @@ -122,7 +122,7 @@ - (void)updateVisualsPressed:(BOOL)pressed { newAttrs[NSStrikethroughColorAttributeName] = color; } if (bgColor) { - newAttrs[MentionBackgroundAttributeName] = + newAttrs[[MentionStyle getBackgroundAttributeName]] = [bgColor colorWithResolvedAlpha]; } From a1962b78507cdaa7540dbdb5af48b84e2e64370f Mon Sep 17 00:00:00 2001 From: relextm19 Date: Mon, 9 Nov 2026 14:20:15 +0100 Subject: [PATCH 15/18] fix: revert the podfile.lock --- apps/example/ios/Podfile.lock | 162 +++++++++++++++++----------------- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/apps/example/ios/Podfile.lock b/apps/example/ios/Podfile.lock index e7a4e4435..cbcb748e6 100644 --- a/apps/example/ios/Podfile.lock +++ b/apps/example/ios/Podfile.lock @@ -2063,95 +2063,95 @@ EXTERNAL SOURCES: :path: build/rncore-facades/Yoga SPEC CHECKSUMS: - boost: 8502bfdc46e2804408af2e163049ece181009af4 - DoubleConversion: 501a575c40c0b50c89685762dd3e415e6bb26fb0 - fast_float: 7c925d1cebf8328d4018d061f49377e9f887e3b4 - FBLazyVector: fdebac2dfe9c53bca49f8218fbdf1e24e36c8be0 - fmt: ba0886e864ebb21d14c98b2e12e164b8002f5b93 - glog: 3cf7cb46f743c4bc758ae3e6d9c15bd1b4cfd6d4 + boost: 2a9d6e1d9873337543f08d9dbc007b288f4e113b + DoubleConversion: e85e4faac763226bfd1cc4c6a98d8355149b27a5 + fast_float: 908e5ee35999f3d91af4b962ac951acac591866c + FBLazyVector: 953381a667ad5f4119b929026e53c4f3aa0da7e7 + fmt: c7776a2a4b1d7ce88b809a1e4d1f7add0f2369df + glog: b4427c3119645da795ff09985ba9da909c940c96 hermes-engine: a1158910bb7e300b9e3d2f1e2d433f817ec1a4b5 - RCT-Folly: 82921e585c0400eda46fac1068297aa9dfb035e4 - RCTDeprecation: e134f2a2c096a6450f5fcbbe949531f913a2ff04 - RCTRequired: f1a68295837ee8f91e112ed1b5694d12e7ff1784 + RCT-Folly: d173e541eeb78cad5c81011c1bbf62d5b86b9778 + RCTDeprecation: b5015bad0dc536eff092b252e8cdcf7903448e03 + RCTRequired: 1f568a6519677ef482387250f5a098a9ec5dba57 RCTSwiftUI: 4b21ec5b1f86acb9c96bb429100ad88d4023ed76 - RCTSwiftUIWrapper: 68bd9fac4e710259cb2b202472adc5f4d113e872 + RCTSwiftUIWrapper: 118a21dd01e8000e0583f5f5660a815975aa9cf5 RCTTypeSafety: 77078a9c26030dd84a6bdae74ed900159f89a098 React: 8dafd0ef058191e9e7238cfa6b3deaa24398e5dd - React-bridging: 658efeb1b4704d5f60ea2fb6e8ca826ab0ae3234 - React-callinvoker: 4e40c208c1ea46686c084a7c23da6a65cbb99482 - React-Core: a831be15fcea0e345a24cb10d6cc0b87e9913d03 - React-Core-prebuilt: 0fd2555a42f40e7770ced1c7dfc5ee1dbfe041cd - React-CoreModules: a86fbe698fd817c17b3936832dc1106a130c4694 - React-cxxreact: 48ca56bd4f26de869478a803a5544b101a57cde6 + React-bridging: af8fb3f4aebda43f116b69d08384bc3058940b24 + React-callinvoker: 990aad7c20625b59200be77eea7f21f80280a9db + React-Core: f9dd5e5a1c462c8bed235c305c2e2309dfc105f8 + React-Core-prebuilt: 9e4e8e87cae574b60a941e4ce6b621911e4d5cf3 + React-CoreModules: fe68e8743f1586a0557fe8d754b34c0c8d8c5b74 + React-cxxreact: 4a05b5c0a8d75d56816529edbc02beab1606e216 React-cxxstableapi: f35502b4c542a0d44031b42f91c4ca813d267e16 - React-debug: 238e15d17dfded9419a6d739d4c8b60968bad02e - React-defaultsnativemodule: c028edc7e48914344b823931aec1cc4ffabe631e - React-domnativemodule: b09770fc69f5ce5759de98f8065cab900b6d87d6 - React-Fabric: a157c978603fa2796f349f3a27d17861e55804c5 - React-FabricComponents: c7c58a1deea5db215e9d5a2aec890e208d5d5075 - React-FabricImage: 234346bf5a3ef918f3873e845b57b93b2b1f31c0 - React-featureflags: a00ac5c38e63d5f86de895ca923f07f5ff76de66 - React-featureflagsnativemodule: 6b93ba0aef46757b9d54166475abc5e4fa80e70d - React-graphics: 634bc2e5884b4a29f56aa8aef719e03171a23f6b - React-hermes: 9ce7aaf6784709e196ac51bfd89dd6c551e3fb4c - React-idlecallbacksnativemodule: e02e194086278377ced48b7fd7816b6c925b9e7e - React-ImageManager: 452d4b3587f21d3384868e2abaab7c0a952b1d1c - React-intersectionobservernativemodule: 3ddbc206bc95c086f1df6eea04aa617ae02627d2 - React-jserrorhandler: a0d842e1f74cc10e597fde2a6447860483df2b13 - React-jsi: 489de0620905b88a17ccb0ac2328046af43e7ebd - React-jsiexecutor: f0e2ae6d98b587d3505ebde246599ee3ad97cee1 - React-jsinspector: 515bf11caeda5df444f39aec63e377ef77ad7696 - React-jsinspectorcdp: be9ac71a77880a6fcc95375e7e61a79e152a3203 - React-jsinspectornetwork: a4bc1475897a2301d114d7a8605af3e8760f9e52 - React-jsinspectortracing: 7d35952c944dc337d1a4167605c1338108880219 - React-jsitooling: 1886dc5058e9feded2136b0d9ba5c189c6af5faa - React-jsitracing: 76b58feee3fb0539c8967e5b9de1a40ad8014f09 - React-logger: 3d2b406a780fed50ad0bbd07452b373c2a515308 - React-Mapbuffer: a2dae4f2cb335ebb97f2240494d0c2bab84cd339 - React-microtasksnativemodule: 8b3aaa5f3b907ecf071b105589868d9f027a448d - React-mutationobservernativemodule: 11d77d3f7360578f07847843544ada23cc473049 - react-native-image-picker: dc809b800c612d43b6508095cca505c32cf9d3c8 - React-NativeModulesApple: 52f3def085f129de1307e3eb78e26729ff70f421 - React-networking: 1e6441349ac72bfd4f7a79c300c3dd76993a7058 - React-oscompat: e64123dd8199f9e99cede19fa542c3da3445481e - React-perflogger: f1466e0f46ce706aef73a559337eca85f51a40b7 - React-performancecdpmetrics: f238752e99eb7c69c782020827bff38a4b1b2ef2 - React-performancetimeline: f1b216fa02200c859cd18ef345d4230cd712137a + React-debug: 225d5d56d096312e1a744b6839a2ad929258b2dd + React-defaultsnativemodule: e88fa0070d99850f11ca368be23f5bd960f9dcdc + React-domnativemodule: 45f2a0aac0866d0da969125eb0c67cecea189180 + React-Fabric: 15c7c42e5faef29d76e398824556f7cf9cc04d35 + React-FabricComponents: 3025339f15ac4715de8a2619a3146c842035bd26 + React-FabricImage: cc00f781af90a934f35c1050466b18fddd86d4cd + React-featureflags: 548879104928d75f937bdea454ce0cb89673878a + React-featureflagsnativemodule: 30eed289f12d51ba7a9744545d783fcfc76b71fd + React-graphics: 69c2173051f1cfa5daf370d5e2c2e1783a621129 + React-hermes: 42d3b1d6de9857595c256eb8996bb106ed40e0ed + React-idlecallbacksnativemodule: 6cc2ba62bb034708f6dd90e61a65a1eb7d3e3bcf + React-ImageManager: 2cdaadea57d74052a6548155e157e6b10e813bd2 + React-intersectionobservernativemodule: 0bcd8856f0eabff39b8f3ba0203b87b0d1d3fca2 + React-jserrorhandler: f10ca6b509737a3f872eb6aafe97fd4394ce33d9 + React-jsi: f85e93f9b8d40804731d90b49165b2a9dd842d81 + React-jsiexecutor: 46ef706cd6a6078ded3338b45bb954e7895505bc + React-jsinspector: 378fea230352b1c00d497283b24df340743627cd + React-jsinspectorcdp: b48d8a2931f505fb71213facf4668db6b0d714e3 + React-jsinspectornetwork: 24f58d9def362e363b3aa7d3f65f1bbdd340396b + React-jsinspectortracing: 31f12c0953ecf1bc98872398cb15e6907cc89aa7 + React-jsitooling: b81a8421cd105cfa04d5575192dee261f719c243 + React-jsitracing: d502415ab958446c09c164a0378d62a61be2b438 + React-logger: 08a3fb49d43447115f6a094cbbe4aaba308d4ed0 + React-Mapbuffer: ebfc6ddeba62b89b3118ab9206e83b8ad1419123 + React-microtasksnativemodule: b8478c203a5d65f5729a5d72564b5625306246d2 + React-mutationobservernativemodule: 4b42b9a136d149799864720e5201a9ce190d2bef + react-native-image-picker: f166d85a3fbdc52ac9ed01062250140c44ba247b + React-NativeModulesApple: cb7ad2bcca44bc4e65eff580b7a7c2d2c6914fa0 + React-networking: 71c78b3c3afca071b8534b10ee501177b7938c9b + React-oscompat: 15c32b3f1e17618e60658411167c2746857fbba5 + React-perflogger: 7997b8eaa3d953be049f3897f9796a1c1eaefdc7 + React-performancecdpmetrics: 1f1cb4196ce97621504a11cd1a106fcd76660b6f + React-performancetimeline: 60f947e3384c00396e71bbb9548e112a94eb13a8 React-RCTActionSheet: 81662769b1f576e9c2e074deb41d6b83d1c7e29f - React-RCTAnimatedModuleProvider: a9829773197f782c19ad86c5438a2cc199203774 - React-RCTAnimation: ad9dd2c6c3b4d07e583c2b79354858c4f34481a0 - React-RCTAppDelegate: 70398a06e10ada27cdf77dc2b43f883126a91ac0 - React-RCTBlob: f3d86b491b8f28c36ced0cb750878b62f72e1380 - React-RCTFabric: 3767f97183c40ba3dadf007b17a01be2cd4e632a - React-RCTFBReactNativeSpec: d7ad5d9edc1865f38b9aac5b7091c3abb6978eed - React-RCTImage: 46ad408f777dce991d4095d7e73a568212be6baa - React-RCTLinking: 547427cc885bfa74b3cbba405971c5270defde7a - React-RCTNetwork: 52c00c0fe07327df9b9fe9881b4f5550dc5ced37 - React-RCTRuntime: 081fd457d305c3aee76c335c568e693ed107f48e - React-RCTSettings: 9cd0b2be41404574ec280b6b8e73c2208c842050 - React-RCTText: 5a6d38456eabc0a1a7c0d47d592390d35c6de57c - React-RCTVibration: c1815b4f471462954a4b7d8835155e053cec5412 + React-RCTAnimatedModuleProvider: e71da181d50d3d19ab5fa24ace7b9cef67453ba2 + React-RCTAnimation: d900133c5fd04ea66576c0221e369be255aa27c8 + React-RCTAppDelegate: 8190863c58350373cc2929ef8b22faeaeaa3fa5f + React-RCTBlob: 7d6a4709dcd74281b6d0e8ccd10e2847f3c882fb + React-RCTFabric: 9a34936cb16f86e90fc4e5911ca068c43db78c0f + React-RCTFBReactNativeSpec: d9f8c284e5d965bd7a2a718e06b076204c383394 + React-RCTImage: 5d62b5686350935a52e0bc5c961339476a0da0d9 + React-RCTLinking: 5a019526644083957085610a3399094fd8d0819e + React-RCTNetwork: a7b8711829339321eb368aa1708f35b55a9e5e82 + React-RCTRuntime: a745878bbad8ba81420e95030b317c2116a3ae33 + React-RCTSettings: 9ac026a882b58f12c8ddaff02df4e60988439310 + React-RCTText: f9bf7738a96fc25968857f4c1c4d5c4257874b41 + React-RCTVibration: 400e227a70dfdf7c0924cd990c54c57fbcb194d1 React-rendererconsistency: b7996da82c8d3f4a7928b39be3e437b72ad92012 - React-renderercss: 4c256900eba87661178771766da0171493f88848 - React-rendererdebug: 4d9df8cf2cac6eee7002a4d14358c79fdf6ad8c5 - React-resizeobservernativemodule: 750d334554e7c44bacf14568a8a0d0048cc4c278 - React-RuntimeApple: 2045a6206895ad5ce90d141d1bd384888fd06c42 - React-RuntimeCore: b051facffbc7ca038097278cabf810d6d86dd328 - React-runtimeexecutor: b06ec9bb745a97cbd3ce25e3e02be7b8058fb374 - React-RuntimeHermes: fcfa8baca49a6d37d331147568d51d5b8b0a175d - React-runtimescheduler: c2afe74d1db006bafd9270186101f5378b1bef81 - React-timing: 6a1a8cfb0caae8de243aba16fa92fa81de23efaf - React-utils: 2384e5db98378df8c0bf2c0d5489ec1b8e80b398 - React-viewtransitionnativemodule: 8505b253586f792c6c722869a664889797ecae3e - React-webperformancenativemodule: 67f32fde92ed7e8470ee1c669bdb7c2fcb760141 - ReactAppDependencyProvider: 782ee9546c9cd3b53b73f1e9e3dd728540085fc7 - ReactCodegen: 7b71f4464442e9b6eae41094d11076d56c51c0e3 - ReactCommon: 145a14b942b19fc2fe38927f261955ada56978aa + React-renderercss: 3b11f40c0c21140902dee115e8fefcf59f75c703 + React-rendererdebug: 331a5c2ebf9294b82eb3531e0e1efbaa0537a0bb + React-resizeobservernativemodule: 24a21a6d00e9dd360f4ef8bf4065040a8b5bc985 + React-RuntimeApple: 0aaf9964151b80c9efc8fd08a80e96ec9c7d60dd + React-RuntimeCore: df973653596b10d77a497c2c34a9f8325c307249 + React-runtimeexecutor: 5c613fede1667a12a38cfc566ff3026bfde3b5f7 + React-RuntimeHermes: d7bcefa9b395d1646c906c4112a1f8de7212e90b + React-runtimescheduler: 431db4de0f22bb2b3315cb728ac8983a566c955a + React-timing: 1d927443f5c37bb25dee28478ef1f20f05996626 + React-utils: d50a630c236f386a9ac019f360faf661e5c4717e + React-viewtransitionnativemodule: 8b0ce65faa32cdfc14aaa89680711cca3321c180 + React-webperformancenativemodule: 087b85db47f4e83dd719a03822986b6c2f073335 + ReactAppDependencyProvider: 1666a962dbb4b36824b6297f5fc83049dd7c3717 + ReactCodegen: 5b3cdb1f612a81f3b543a94f425ecd8518c32f2c + ReactCommon: c6895b36d81986f89a7e40a00b4b72ca70e82710 ReactNativeDependencies: d3b7423ba1e52525e42085c8470109abde583d2e - ReactNativeEnrichedHtml: a90b3959b4ec18a1001a47d6c63fd567aeedf7d4 - SocketRocket: 37aec555668fb852ec12e3c0de59a86ca58f0871 - Yoga: d1c536142c5ff8ec8cd856ab2a7c227a1d875c8e + ReactNativeEnrichedHtml: 0575ded0afcd0b6b242d24011b8761925f4a0767 + SocketRocket: d57b1af80c029e12a75cd9b218287c67381e4593 + Yoga: 58b502c52b14ad3c4468805d461fc37d275c2a42 PODFILE CHECKSUM: 17de42bc1248ff5392a5a74f9edf4660b05a1695 -COCOAPODS: 1.17.0 +COCOAPODS: 1.15.2 From 7f264788b4e2bbb5564eec11c694782c2cf8deb1 Mon Sep 17 00:00:00 2001 From: relextm19 Date: Tue, 10 Nov 2026 11:14:36 +0100 Subject: [PATCH 16/18] fix(android): clip border to text bounds --- .../common/MentionBackgroundDrawer.kt | 65 ++++++++++++------- .../enriched/text/EnrichedTextView.kt | 1 + .../textinput/EnrichedTextInputView.kt | 1 + 3 files changed, 45 insertions(+), 22 deletions(-) diff --git a/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt b/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt index a5945964e..7ab7b248d 100644 --- a/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt +++ b/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt @@ -7,6 +7,7 @@ import android.graphics.Path import android.graphics.RectF import android.text.Layout import android.text.Spanned +import android.widget.TextView import com.swmansion.enriched.common.spans.EnrichedMentionSpan // Mention backgrounds are drawn by the view instead of the span, because spans only get whole-line @@ -17,15 +18,35 @@ object MentionBackgroundDrawer { private val rect = RectF() private val radii = FloatArray(8) + fun clipToTextBounds( + canvas: Canvas, + view: TextView, + layout: Layout, + ) { + val scrollX = view.scrollX + val scrollY = view.scrollY + val verticalSpace = view.height - view.compoundPaddingTop - view.compoundPaddingBottom + val maxScrollY = layout.height - verticalSpace + + val clipLeft = (view.compoundPaddingLeft + scrollX).toFloat() + val clipTop = if (scrollY == 0) 0f else (view.extendedPaddingTop + scrollY).toFloat() + val clipRight = (view.width - view.compoundPaddingRight + scrollX).toFloat() + val clipBottom = + (view.height + scrollY - if (scrollY == maxScrollY) 0 else view.extendedPaddingBottom) + .toFloat() + + canvas.clipRect(clipLeft, clipTop, clipRight, clipBottom) + } + // Must be called with the canvas translated to the layout origin, before the text is drawn. fun draw( - canvas: Canvas, - layout: Layout, - text: Spanned, - style: EnrichedStyle, - backgroundColorFor: (EnrichedMentionSpan, MentionStyle) -> Int = { _, mentionStyle -> - mentionStyle.backgroundColor - }, // lambda to handle press state bg color for enrichedText + canvas: Canvas, + layout: Layout, + text: Spanned, + style: EnrichedStyle, + backgroundColorFor: (EnrichedMentionSpan, MentionStyle) -> Int = { _, mentionStyle -> + mentionStyle.backgroundColor + }, // lambda to handle press state bg color for enrichedText ) { val spans = text.getSpans(0, text.length, EnrichedMentionSpan::class.java) for (span in spans) { @@ -42,11 +63,11 @@ object MentionBackgroundDrawer { } private fun drawSpanBackground( - canvas: Canvas, - layout: Layout, - start: Int, - end: Int, - radius: Float, + canvas: Canvas, + layout: Layout, + start: Int, + end: Int, + radius: Float, ) { val firstLine = layout.getLineForOffset(start) val lastLine = layout.getLineForOffset(end - 1) @@ -56,19 +77,19 @@ object MentionBackgroundDrawer { val isLast = line == lastLine val segmentStart = - if (isFirst) layout.getPrimaryHorizontal(start) else layout.getLineLeft(line) + if (isFirst) layout.getPrimaryHorizontal(start) else layout.getLineLeft(line) val segmentEnd = - if (isLast) { - layout.getPrimaryHorizontal(end) - } else { - layout.getLineRight(line) - } + if (isLast) { + layout.getPrimaryHorizontal(end) + } else { + layout.getLineRight(line) + } rect.set( - segmentStart, - layout.getLineTop(line).toFloat(), - segmentEnd, - layout.getLineBottom(line).toFloat(), + segmentStart, + layout.getLineTop(line).toFloat(), + segmentEnd, + layout.getLineBottom(line).toFloat(), ) // Only round the outer ends of a wrapped mention. diff --git a/android/src/main/java/com/swmansion/enriched/text/EnrichedTextView.kt b/android/src/main/java/com/swmansion/enriched/text/EnrichedTextView.kt index efcb9fde5..8cf10c70a 100644 --- a/android/src/main/java/com/swmansion/enriched/text/EnrichedTextView.kt +++ b/android/src/main/java/com/swmansion/enriched/text/EnrichedTextView.kt @@ -100,6 +100,7 @@ class EnrichedTextView : AppCompatTextView { val style = enrichedStyle if (currentLayout != null && spanned != null && style != null) { canvas.save() + MentionBackgroundDrawer.clipToTextBounds(canvas, this, currentLayout) canvas.translate(totalPaddingLeft.toFloat(), totalPaddingTop.toFloat()) MentionBackgroundDrawer.draw(canvas, currentLayout, spanned, style) { span, mentionStyle -> val isPressed = (span as? EnrichedTextClickableSpan)?.isPressed == true diff --git a/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputView.kt b/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputView.kt index 31d9bee22..9772099bd 100644 --- a/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputView.kt +++ b/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputView.kt @@ -300,6 +300,7 @@ class EnrichedTextInputView : val currentText = text if (currentLayout != null && currentText != null) { canvas.save() + MentionBackgroundDrawer.clipToTextBounds(canvas, this, currentLayout) canvas.translate(totalPaddingLeft.toFloat(), totalPaddingTop.toFloat()) MentionBackgroundDrawer.draw(canvas, currentLayout, currentText, htmlStyle) canvas.restore() From ccc5b2e0ee90cdf8ed190c0f6ccf3e45ac0b1ffe Mon Sep 17 00:00:00 2001 From: relextm19 Date: Tue, 10 Nov 2026 11:40:45 +0100 Subject: [PATCH 17/18] feat(android): only draw the visible lines --- .../common/MentionBackgroundDrawer.kt | 28 ++++++++++++++++--- apps/example/src/constants/editorConfig.ts | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt b/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt index 7ab7b248d..7b9515bb5 100644 --- a/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt +++ b/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt @@ -4,6 +4,7 @@ import android.graphics.Canvas import android.graphics.Color import android.graphics.Paint import android.graphics.Path +import android.graphics.Rect import android.graphics.RectF import android.text.Layout import android.text.Spanned @@ -17,6 +18,7 @@ object MentionBackgroundDrawer { private val path = Path() private val rect = RectF() private val radii = FloatArray(8) + private val clipBounds = Rect() fun clipToTextBounds( canvas: Canvas, @@ -38,7 +40,8 @@ object MentionBackgroundDrawer { canvas.clipRect(clipLeft, clipTop, clipRight, clipBottom) } - // Must be called with the canvas translated to the layout origin, before the text is drawn. + // Must be called with the canvas translated to the layout origin and clipped to the visible text + // area before the text is drawn. Only lines inside the clip are drawn. fun draw( canvas: Canvas, layout: Layout, @@ -48,7 +51,14 @@ object MentionBackgroundDrawer { mentionStyle.backgroundColor }, // lambda to handle press state bg color for enrichedText ) { - val spans = text.getSpans(0, text.length, EnrichedMentionSpan::class.java) + if (!canvas.getClipBounds(clipBounds)) return + + val firstVisibleLine = layout.getLineForVertical(clipBounds.top) + val lastVisibleLine = layout.getLineForVertical(clipBounds.bottom) + val visibleStart = layout.getLineStart(firstVisibleLine) + val visibleEnd = layout.getLineEnd(lastVisibleLine) + + val spans = text.getSpans(visibleStart, visibleEnd, EnrichedMentionSpan::class.java) for (span in spans) { val mentionStyle = style.mentionsStyle[span.getIndicator()] ?: continue val color = backgroundColorFor(span, mentionStyle) @@ -58,7 +68,15 @@ object MentionBackgroundDrawer { val end = text.getSpanEnd(span) paint.color = color - drawSpanBackground(canvas, layout, start, end, mentionStyle.borderRadius) + drawSpanBackground( + canvas, + layout, + start, + end, + mentionStyle.borderRadius, + firstVisibleLine, + lastVisibleLine, + ) } } @@ -68,11 +86,13 @@ object MentionBackgroundDrawer { start: Int, end: Int, radius: Float, + firstVisibleLine: Int, + lastVisibleLine: Int, ) { val firstLine = layout.getLineForOffset(start) val lastLine = layout.getLineForOffset(end - 1) - for (line in firstLine..lastLine) { + for (line in maxOf(firstLine, firstVisibleLine)..minOf(lastLine, lastVisibleLine)) { val isFirst = line == firstLine val isLast = line == lastLine diff --git a/apps/example/src/constants/editorConfig.ts b/apps/example/src/constants/editorConfig.ts index f3b20aacf..aed405450 100644 --- a/apps/example/src/constants/editorConfig.ts +++ b/apps/example/src/constants/editorConfig.ts @@ -113,7 +113,7 @@ export const htmlStyle = { color: 'green', backgroundColor: 'lightgreen', textDecorationLine: 'none', - borderRadius: 0, + borderRadius: 20, }, }, ol: { From 46339467f6dc1ecfa2d29dd7fef253440e15a3d1 Mon Sep 17 00:00:00 2001 From: relextm19 Date: Tue, 10 Nov 2026 11:45:03 +0100 Subject: [PATCH 18/18] feat: add docs for border radius --- .../common/MentionBackgroundDrawer.kt | 72 +++++++++---------- apps/example/src/constants/editorConfig.ts | 2 +- .../docs/api-reference/enriched-text-input.md | 4 ++ docs/docs/api-reference/enriched-text.md | 1 + .../styling-the-input.mdx | 22 +++--- 5 files changed, 53 insertions(+), 48 deletions(-) diff --git a/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt b/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt index 7b9515bb5..c3661ece0 100644 --- a/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt +++ b/android/src/main/java/com/swmansion/enriched/common/MentionBackgroundDrawer.kt @@ -21,9 +21,9 @@ object MentionBackgroundDrawer { private val clipBounds = Rect() fun clipToTextBounds( - canvas: Canvas, - view: TextView, - layout: Layout, + canvas: Canvas, + view: TextView, + layout: Layout, ) { val scrollX = view.scrollX val scrollY = view.scrollY @@ -34,8 +34,8 @@ object MentionBackgroundDrawer { val clipTop = if (scrollY == 0) 0f else (view.extendedPaddingTop + scrollY).toFloat() val clipRight = (view.width - view.compoundPaddingRight + scrollX).toFloat() val clipBottom = - (view.height + scrollY - if (scrollY == maxScrollY) 0 else view.extendedPaddingBottom) - .toFloat() + (view.height + scrollY - if (scrollY == maxScrollY) 0 else view.extendedPaddingBottom) + .toFloat() canvas.clipRect(clipLeft, clipTop, clipRight, clipBottom) } @@ -43,13 +43,13 @@ object MentionBackgroundDrawer { // Must be called with the canvas translated to the layout origin and clipped to the visible text // area before the text is drawn. Only lines inside the clip are drawn. fun draw( - canvas: Canvas, - layout: Layout, - text: Spanned, - style: EnrichedStyle, - backgroundColorFor: (EnrichedMentionSpan, MentionStyle) -> Int = { _, mentionStyle -> - mentionStyle.backgroundColor - }, // lambda to handle press state bg color for enrichedText + canvas: Canvas, + layout: Layout, + text: Spanned, + style: EnrichedStyle, + backgroundColorFor: (EnrichedMentionSpan, MentionStyle) -> Int = { _, mentionStyle -> + mentionStyle.backgroundColor + }, // lambda to handle press state bg color for enrichedText ) { if (!canvas.getClipBounds(clipBounds)) return @@ -69,25 +69,25 @@ object MentionBackgroundDrawer { paint.color = color drawSpanBackground( - canvas, - layout, - start, - end, - mentionStyle.borderRadius, - firstVisibleLine, - lastVisibleLine, + canvas, + layout, + start, + end, + mentionStyle.borderRadius, + firstVisibleLine, + lastVisibleLine, ) } } private fun drawSpanBackground( - canvas: Canvas, - layout: Layout, - start: Int, - end: Int, - radius: Float, - firstVisibleLine: Int, - lastVisibleLine: Int, + canvas: Canvas, + layout: Layout, + start: Int, + end: Int, + radius: Float, + firstVisibleLine: Int, + lastVisibleLine: Int, ) { val firstLine = layout.getLineForOffset(start) val lastLine = layout.getLineForOffset(end - 1) @@ -97,19 +97,19 @@ object MentionBackgroundDrawer { val isLast = line == lastLine val segmentStart = - if (isFirst) layout.getPrimaryHorizontal(start) else layout.getLineLeft(line) + if (isFirst) layout.getPrimaryHorizontal(start) else layout.getLineLeft(line) val segmentEnd = - if (isLast) { - layout.getPrimaryHorizontal(end) - } else { - layout.getLineRight(line) - } + if (isLast) { + layout.getPrimaryHorizontal(end) + } else { + layout.getLineRight(line) + } rect.set( - segmentStart, - layout.getLineTop(line).toFloat(), - segmentEnd, - layout.getLineBottom(line).toFloat(), + segmentStart, + layout.getLineTop(line).toFloat(), + segmentEnd, + layout.getLineBottom(line).toFloat(), ) // Only round the outer ends of a wrapped mention. diff --git a/apps/example/src/constants/editorConfig.ts b/apps/example/src/constants/editorConfig.ts index aed405450..f3b20aacf 100644 --- a/apps/example/src/constants/editorConfig.ts +++ b/apps/example/src/constants/editorConfig.ts @@ -113,7 +113,7 @@ export const htmlStyle = { color: 'green', backgroundColor: 'lightgreen', textDecorationLine: 'none', - borderRadius: 20, + borderRadius: 0, }, }, ol: { diff --git a/docs/docs/api-reference/enriched-text-input.md b/docs/docs/api-reference/enriched-text-input.md index eb4339d43..f3b12adc0 100644 --- a/docs/docs/api-reference/enriched-text-input.md +++ b/docs/docs/api-reference/enriched-text-input.md @@ -1223,6 +1223,7 @@ interface MentionStyleProperties { color?: ColorValue; backgroundColor?: ColorValue; textDecorationLine?: 'underline' | 'none'; + borderRadius?: number; } ``` @@ -1278,6 +1279,9 @@ should be a record with indicators as keys and configs as values. [color](https://reactnative.dev/docs/colors) value, defaults to `yellow` - `textDecorationLine` - whether mentions are underlined; `'underline'` or `'none'`, defaults to `'underline'` +- `borderRadius` - corner radius of the mention background; defaults to `0`. + When a mention wraps onto multiple lines, only its outer corners (at the + start of the first line and the end of the last line) are rounded :::tip diff --git a/docs/docs/api-reference/enriched-text.md b/docs/docs/api-reference/enriched-text.md index 7c9e6fc82..7f03c96b1 100644 --- a/docs/docs/api-reference/enriched-text.md +++ b/docs/docs/api-reference/enriched-text.md @@ -260,6 +260,7 @@ interface EnrichedTextMentionStyleProperties { color?: ColorValue; backgroundColor?: ColorValue; textDecorationLine?: 'underline' | 'none'; + borderRadius?: number; pressColor?: ColorValue; pressBackgroundColor?: ColorValue; } diff --git a/docs/docs/core-functionalities/styling-the-input.mdx b/docs/docs/core-functionalities/styling-the-input.mdx index 26ba3c24a..8b4d32f98 100644 --- a/docs/docs/core-functionalities/styling-the-input.mdx +++ b/docs/docs/core-functionalities/styling-the-input.mdx @@ -62,17 +62,17 @@ to their React Native `TextStyle` counterparts. Some are platform-limited `htmlStyle` maps each supported element to a small config object. Anything you omit falls back to the built-in default. The available keys are: -| Key | Styles | Notable options | -| ------------ | -------------- | ----------------------------------------------------------- | -| `h1`–`h6` | Headings | `fontSize`, `bold` | -| `blockquote` | Blockquote | `borderColor`, `borderWidth`, `gapWidth`, `color` | -| `codeblock` | Code block | `color`, `backgroundColor`, `borderRadius` | -| `code` | Inline code | `color`, `backgroundColor` | -| `a` | Links | `color`, `textDecorationLine` | -| `mention` | Mentions | `color`, `backgroundColor`, `textDecorationLine` | -| `ol` | Ordered list | `markerColor`, `markerFontWeight`, `marginLeft`, `gapWidth` | -| `ul` | Unordered list | `bulletColor`, `bulletSize`, `marginLeft`, `gapWidth` | -| `ulCheckbox` | Checkbox list | `boxColor`, `boxSize`, `marginLeft`, `gapWidth` | +| Key | Styles | Notable options | +| ------------ | -------------- | ---------------------------------------------------------------- | +| `h1`–`h6` | Headings | `fontSize`, `bold` | +| `blockquote` | Blockquote | `borderColor`, `borderWidth`, `gapWidth`, `color` | +| `codeblock` | Code block | `color`, `backgroundColor`, `borderRadius` | +| `code` | Inline code | `color`, `backgroundColor` | +| `a` | Links | `color`, `textDecorationLine` | +| `mention` | Mentions | `color`, `backgroundColor`, `textDecorationLine`, `borderRadius` | +| `ol` | Ordered list | `markerColor`, `markerFontWeight`, `marginLeft`, `gapWidth` | +| `ul` | Unordered list | `bulletColor`, `bulletSize`, `marginLeft`, `gapWidth` | +| `ulCheckbox` | Checkbox list | `boxColor`, `boxSize`, `marginLeft`, `gapWidth` | The full list of properties, defaults, and platform notes lives in the [`EnrichedTextInput`](/api-reference/enriched-text-input#htmlstyle) reference.