Skip to content

fix(android,core): preserve inline-flex child layout inside block parents - #248

Open
herefishyfish wants to merge 2 commits into
triniwiz:mainfrom
herefishyfish:fix/inline-flex-in-block
Open

herefishyfish wants to merge 2 commits into
triniwiz:mainfrom
herefishyfish:fix/inline-flex-in-block

Conversation

@herefishyfish

@herefishyfish herefishyfish commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Why

An element with display: inline-flex (or inline-grid) inside a block parent loses child centering and horizontal padding, leaving children pinned at (0, 0).

Two separate bugs cause this. On Android, Div extends Scroll -> TwoDScrollView -> FrameLayout. When TextView.placeInlineBox calls box.layout(...) during inline-run draw, Scroll.onLayout called super.onLayout, which ran FrameLayout.onLayout and reset Mason-positioned children back to (0, 0). In mason-core, DisplayMode::Box containers marked is_text_container (such as <button>) bypassed flexbox and grid layout in tree.rs and tree_inline.rs.

What changed

  • TwoDScrollView.kt / Scroll.kt add protected open val layoutChildrenInSuper (true on TwoDScrollView, false on Scroll) so Scroll.onLayout keeps scroll-offset bookkeeping while skipping FrameLayout.onLayout.
  • crates/mason-core/src/tree.rs and crates/mason-core/src/tree_inline.rs allow DisplayMode::Box nodes with Display::Flex or Display::Grid and non-empty children to run flexbox/grid layout even when is_text_container is set.
  • Added Rust test inline_flex_text_container_centers_child_and_applies_padding_in_block in crates/mason-core/tests/flex_inline_mix.rs and Android instrumented test inlineFlexDivInBlockKeepsPaddingAndCenteringAfterDraw in InlineRunsInstrumentedTest.kt.

Blast Radius

Skipping FrameLayout.onLayout on Scroll also avoids a redundant child layout pass on every Android Scroll/Div layout. Plain TwoDScrollView subclasses outside Scroll keep layoutChildrenInSuper = true. Leaf TextContainer nodes without children keep their existing measure path.

Verification

  • cargo test -p mason-core --test flex_inline_mix failed before the fix ([block] expected 72x36 inline-flex box, got 92x36) and passed after.
  • cargo test -p mason-core -p mason-c --all-targets passed (0 failed).
  • ./gradlew :masonkit:connectedDebugAndroidTest '-Pandroid.testInstrumentationRunnerArguments.class=org.nativescript.mason.masonkit.InlineRunsInstrumentedTest' on emulator-5554 (API 33) failed before the fix (got left=0) and passed after (8/8 tests passed).

Before / After

Before and after: inline-flex inside block vs flex parent

This branch has not been deployed

No deployments
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.

1 participant