Skip to content

fix(android): flush visual text styles and rebuild spans in TextEngine - #245

Merged
triniwiz merged 2 commits into
triniwiz:mainfrom
herefishyfish:fix/android-text-style-flush
Nov 30, 2026
Merged

triniwiz merged 2 commits into
triniwiz:mainfrom
herefishyfish:fix/android-text-style-flush

Conversation

@herefishyfish

Copy link
Copy Markdown
Contributor

Why

Android TextEngine must apply visual text style updates even when they arrive with unchanged layout flags, and it must clear stale spans when visual styles reset.

Two bugs broke text updates in TextEngine:

  • After signaturesKnown turned true, a batched syncStyleParts containing an unchanged layout flag (FONT_SIZE, FONT_WEIGHT, or TEXT_ALIGN) alongside a new FONT_COLOR dropped the color change. onTextStyleChanged gated textVisualChanged on !textLayoutChanged, and flushTextStyleIfNeeded returned early when the layout signature matched.
  • Resetting text-decoration from line-through to none (or updating decoration color and flattened child decorations) left stale Spans.DecorationSpan entries rendered. redrawAfterVisualChange only invalidated segments when preparedRun != null && preparableChild() == null, so non-prepared text kept returning cached cachedAttributedString and StaticLayout instances.

What changed

  • TextEngine.onTextStyleChanged tracks textVisualChanged independently of textLayoutChanged, sets both pending flush flags, and invalidates the view whenever visual flags change so quiet compute-entry flushes still repaint.
  • TextEngine.flushTextStyleIfNeeded falls through from layoutPending to visualPending when textLayoutSignature() matches lastTextLayoutSignature.
  • TextEngine.redrawAfterVisualChange increments segmentsInvalidateVersion, clears cachedAttributedString, calls TextView.clearCachedStaticLayouts(), marks staleMeasures when a text becomes preparable again, and propagates visual invalidation to a flattening parent TextContainer.
  • TextView.clearCachedStaticLayouts exposes an internal helper to clear both cachedStaticLayout and floatAwareStaticLayout.
  • TextStyleFlushInstrumentedTest adds Android instrumentation coverage for both bugs under prepared and non-prepared text paths, quiet flushes, decoration color updates, and flattened child Span elements.

Scope

Android masonkit Kotlin sources and instrumentation tests only (TextEngine.kt, TextView.kt, and TextStyleFlushInstrumentedTest.kt). No public API signatures or native Rust code changed.

Blast Radius

Scoped to Android text style flushing and visual redraws in TextEngine and TextView. Pure color updates on a PreparedRun keep the prepared fast path intact and do not bump segmentsInvalidateVersion.

Verification

  • Before the fix, gradlew :masonkit:connectedReleaseAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=org.nativescript.mason.masonkit.TextStyleFlushInstrumentedTest failed all 4 tests on an Android 13 (API 33) emulator with 0 dark pixels on both batched color tests, expected:<0> but was:<1> DecorationSpan after resetting line-through, and stale Color.RED instead of Color.BLUE.
  • After the fix, all 43 tests across TextStyleFlushInstrumentedTest, PreparedTextParityTest, InheritedTextStyleInstrumentedTest, TextContentAttributesInstrumentedTest, FlexTextAlignmentInstrumentedTest, ForeignStyleSyncInstrumentedTest, InlineRunsInstrumentedTest, and NestedTextRunsInstrumentedTest passed on API 33 (43/43, 0 skipped, 0 failed).
  • gradlew :masonkit:testReleaseUnitTest passed (BUILD SUCCESSFUL).

@triniwiz
triniwiz merged commit b509f5e into triniwiz:main Nov 30, 2026
1 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants