← 输入框|github.com|刷新
Skip to content

fix(android): ContentLayout measures children against unreduced parent spec - #11439

Merged
NathanWalker merged 2 commits into
mainfrom
fix/android-contentlayout-child-measure-inset
Sep 23, 2026
Merged

NathanWalker merged 2 commits into
mainfrom
fix/android-contentlayout-child-measure-inset

Conversation

@triniwiz

@triniwiz triniwiz commented Sep 19, 2026 •

Copy link
Copy Markdown
Member

Summary

  • ContentLayout.onMeasure measured children against its own unreduced parent spec, but onLayout places them into the padding-reduced box. With padding present (e.g. edge-to-edge insets applied as padding at targetSdk 35+), children get laid out larger than their box and an ancestor clipChildren=true silently clips the difference.
  • Fixed by deducting the layout's own padding from the child measure spec, matching StackLayout/DockLayout.
  • Also fixes a latent onLayout bug: childBottom incorrectly factored in paddingRight. It must only subtract paddingBottom (mirroring how childTop only adds paddingTop) since CommonLayoutParams.layoutChild's FILL_VERTICAL branch passes top/bottom straight through to the child when there are no margins.
  • Rebuilt widgets-release.aar and native-build-state.json accordingly.

Test plan

  • ./gradlew :widgets:compileReleaseJavaWithJavac
  • ./build.android.sh rebuild
  • node tools/native-state.mjs check android
  • On-device: constructed a real ContentLayout with padding (0/156/0/72) and a MATCH_PARENT child directly via the compiled AAR, confirmed measured height now matches laid-out height (2628/2628, previously 2856/2628 mismatched)

…t spec

ContentLayout.onMeasure passed its own widthMeasureSpec/heightMeasureSpec
straight to measureChild without deducting its own padding first, while
onLayout does respect that padding. When ContentLayout carries padding
(e.g. edge-to-edge system bar insets applied as padding on an ancestor),
children measure against the full parent size but are laid out into the
smaller padding box, and an ancestor with clipChildren=true silently
clips the difference. StackLayout/DockLayout already reduce the spec by
their own padding before measuring children; ContentLayout now does the
same.

Also fixes a latent onLayout typo where childBottom subtracted
paddingRight instead of paddingTop, harmless only when horizontal and
vertical padding happen to match.
@nx-cloud

nx-cloud Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit a50460a

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 3m 37s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-09-19 18:10:47 UTC

@pkg-pr-new

pkg-pr-new Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nativescript/core@11439
npm i https://pkg.pr.new/@nativescript/vite@11439
npm i https://pkg.pr.new/@nativescript/webpack@11439

commit: a50460a

The previous commit's onLayout change used (paddingTop + paddingBottom)
for childBottom, reasoning by analogy with the childTop/childBottom
naming. That's wrong: CommonLayoutParams.layoutChild's FILL_VERTICAL
branch passes the given top/bottom straight through to the child's
final bounds when there are no margins, so childTop already accounts
for paddingTop on its own and childBottom must not subtract it again.

Verified on-device: constructing a real ContentLayout with padding
(0/156/0/72) and a MATCH_PARENT child and comparing measured vs
laid-out height caught this immediately (measured 2628, laid out
2472) before it reached real usage. The correct computation only
drops paddingBottom, matching how childTop only adds paddingTop:

    childBottom = bottom - top - paddingBottom;

Re-verified the same way: measured and laid-out heights now both
report 2628, matching the padded content box exactly.
@NathanWalker
NathanWalker merged commit bda2d8f into main Sep 23, 2026
11 checks passed
@NathanWalker
NathanWalker deleted the fix/android-contentlayout-child-measure-inset branch September 23, 2026 00:01
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