Text + Text concatenation via Compose AnnotatedString#453
Open
vincentborko wants to merge 1 commit into
Open
Conversation
241c381 to
7413efd
Compare
Member
|
We might consider merging this work with #434 to support the |
Contributor
Author
|
Nice idea, I'll update with the best of both worlds shortly! ;) |
`static func + (Text, Text)` was previously `fatalError()`, so any SwiftUI that builds a multi-style inline string by concatenation (per-segment color / weight / size / italic / monospaced / underline / strikethrough / gradient) could not run on Android. Both runtimes now feed one ordered `[TextRun]` model: - Skip Lite (transpiled) via a native `+` operator (`Text.plus`, `// SKIP DECLARE: operator fun plus`), capturing each operand's styling as `TextRunStyle` data (a styled `Text` applies its style as an environment modifier that can't be read back at render time). - SkipFuse via `init(bridgedRuns:colors:fontSizes:fontWeights:flags:)`, which folds primitive per-run descriptors into the same `[TextRun]`. The concatenation *is* a `_Text` carrying its `runs`, folded into a single `AnnotatedString` (each run's styling as a `SpanStyle`) and rendered by the shared `_Text.Render` path — so environment concerns (alignment, line limit + truncation, tracking, line spacing, `material3Text`) behave like any other `Text`, with no duplicated render logic. Pairs with skiptools/skip-fuse-ui#118 (the SkipSwiftUI run model). Bare, unconstrained `Text + Text` requires the transpiler fix in skiptools/skipstone#255 to be composed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
7413efd to
44cb0af
Compare
This was referenced Jun 2, 2026
Contributor
Author
|
all working cleanly now 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Implements
Text + Textconcatenation with per-segment styling on Android, rendered as a single ComposeAnnotatedString.static func + (Text, Text)was previouslyfatalError(), so any SwiftUI that builds a multi-style inline string by concatenation (per-segment color / weight / size / italic / monospaced / underline / strikethrough / gradient foreground) could not run on Android.How
Both runtimes feed one ordered
[TextRun]model, folded into a singleAnnotatedString(each run's styling as aSpanStyle) and rendered by the shared_Text.Renderpath — so environment-level concerns (text alignment, line limit + truncation, tracking, line spacing,material3Text) behave like a normalText, with no duplicated render logic:+operator (Text.plus,// SKIP DECLARE: operator fun plus). A styledTextapplies its style as an environment modifier that can't be read back at render time, so each operand's styling is captured asTextRunStyledata where the modifier is applied (.foregroundColor,.font,.bold, …), mirroring SkipSwiftUI'sTextRun.// SKIP @bridge public init(bridgedRuns:colors:fontSizes:fontWeights:flags:)accepts primitive-only per-run descriptors and folds them into the same[TextRun]. The foreground resolves to a solid color when it is one, otherwise a Compose brush (gradients viaSpanStyle(brush:)).localizedTextString(),asColor, andasBrushare@Composable, so they're resolved in the@Composablescope before the (non-composable) builder lambda.Dependencies / pairing
Text + Text. Without it, an unconstrained concatenation (e.g. directly in aVStack) is constructed but never composed (zero size); it only renders when wrapped in another view modifier like.frame(...).bridgedRunsinitializer.Testing
Verified on an Android emulator (Showcase "Text Concatenation" playground): per-run colors, weights, sizes, italic/monospaced, underline/strikethrough, gradient foreground, and multi-line wrapping all render as a single flowing styled block — both bare/unconstrained and width-constrained.
🤖 Generated with Claude Code