Skip to content

ContentView and Border: hidden content shouldn't take up space - #39560

Merged
kubaflo merged 3 commits into
dotnet:inflight/currentfrom
FullDevStudio:fix/contentview-skip-collapsed-content
Oct 23, 2026
Merged

kubaflo merged 3 commits into
dotnet:inflight/currentfrom
FullDevStudio:fix/contentview-skip-collapsed-content

Conversation

@FullDevStudio

Copy link
Copy Markdown
Contributor

On Android a ContentView or Border kept the full height of its content after we set the content to IsVisible=false. In our app that left a hidden card at 576 dp and the page two thirds empty. On Windows the same layout collapses fine.

MeasureContent measures the content no matter if it's visible. WinUI returns 0 for a collapsed element, but Android measures a GONE view at its full size. The layout managers already skip collapsed children, so I did the same in both MeasureContent overloads and added a unit test for it.

Right now we hide the wrapper instead of the content.

Description of Change

Issues Fixed

Fixes #

kubaflo and others added 3 commits October 21, 2026 14:15
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->

Remove the unused SDK insertion templates instead of migrating their
retired `VSEngSS-MicroBuild2022-1ES` pool:

- `eng/pipelines/common/insertion.yml`
- `eng/pipelines/common/sdk-insertion.yml`

The stage template has no callers, and the job template is referenced
only by that stage. The former `maui-release.yml` caller was removed in
dotnet#31130. The current official build uses Arcade publishing; its
configured YAML entry point and matching `main` revision were checked in
Azure DevOps. The legacy DevDiv MAUI pipeline definitions are disabled.
No active pipeline, publishing stage, or pool is changed.

**Validation:** `git diff --check` passed. PyYAML parsed all 39
remaining pipeline YAML files, and all 113 static local template
references resolved. A tracked-file search found no remaining references
to the retired pool, either deleted template, or the old `sdk_insertion`
stage. No new pipeline tests were added, and no device/UI tests were run
for this configuration-only deletion.

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes dotnet#39518

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 2f892844-9872-4d2f-8799-c45663efc2a3
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->

Explicitly import the installed `Microsoft.PowerShell.Management` and
`Microsoft.PowerShell.Utility` manifests from `$PSHOME` before the
empty-queue helper uses their cmdlets. This avoids relying on automatic
module discovery inside the AWF chroot.

The reported run failed at `Get-Content` even though the queue was
authoritatively empty, so the workflow emitted `report_incomplete`
instead of completing with `noop`. A later scheduled run succeeded with
the unchanged helper, showing that the environment failure is
intermittent.

This five-line change applies to the shared helper used by both `main`
and `net11.0`. Strict snapshot validation, metadata persistence before
expectation registration, registrar exit-code handling, and success-only
`noop` gating are unchanged. No workflow sources, generated locks,
permissions, dependencies, or pipeline tests are changed. This
supplements the helper introduced in dotnet#39237; no competing open fix was
found.

**Validation**

- Reproduced the original `Get-Content` resolution error in a fresh
PowerShell process with `$PSModuleAutoLoadingPreference = 'None'`; the
original helper exited 1 without creating completion artifacts. The
original helper succeeds with normal automatic loading.
- With the change, direct invocations succeed with automatic loading
disabled for both `main`/`ci-scan` and `net11.0`/`ci-scan-net11`. Each
produces zero-byte coverage, the exact summary header, and exactly one
`noop` expectation.
- Mismatched branch/label provenance still exits 1 before creating
completion artifacts.
- `gh aw compile ci-status-fix ci-status-fix-net11 --no-emit --strict
--no-check-update` - passed: 2 workflows succeeded, 0 warnings.
- PowerShell parser validation and `git diff --check` - passed.
- Read-only GPT security review - passed; no confirmed vulnerabilities
or changed credential/sandbox controls.
- Actual [PowerShell CI
run](https://github.com/dotnet/maui/actions/runs/39601588471) on commit
`a55a3923b3aaea22ac74a06b1b4d02979d533366`: **all 23 existing
empty-queue/bootstrap cases passed**, confirmed from the uploaded NUnit
results. The complete suite was **2,624 passed, 3 failed**. All three
failures are the same pre-existing reviewer-model policy assertions seen
in the [earlier main-targeting PR
run](https://github.com/dotnet/maui/actions/runs/39475824752), before
this change: two local-reviewer GPT-5.6 pin assertions and the hosted
review-tests model assertion. Those unrelated tests and model settings
were not changed.

**Hosted boundary:** the failing [reported
run](https://github.com/dotnet/maui/actions/runs/39350684403) and the
later [successful
run](https://github.com/dotnet/maui/actions/runs/39524407970) were
inspected. This patched revision has not been dispatched in the
production AWF chroot; local component reproduction and the passing
helper CI cases are not a claim of hosted deployment verification. Azure
product validation was filtered out by its trigger conditions; the AzDO
build query returned no builds for this PR.

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes dotnet#39476

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8f522b9d-4994-414a-a03e-f3d7a9043385
On Android a ContentView or Border kept the full height of its content
after we set the content to IsVisible=false. In our app that left a
hidden card at 576 dp and the page two thirds empty. On Windows the same
layout collapses fine.

MeasureContent measures the content no matter if it's visible. WinUI
returns 0 for a collapsed element, but Android measures a GONE view at its
full size. The layout managers already skip collapsed children, so I did
the same in both MeasureContent overloads and added a unit test for it.

Right now we hide the wrapper instead of the content.
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 39560

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 39560"

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Oct 22, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @@FullDevStudio! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @FullDevStudio! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@FullDevStudio

Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service agree

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Oct 22, 2026
@kubaflo

This comment has been minimized.

@azure-pipelines

This comment has been minimized.

@kubaflo

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

Tests Failure Analysis

@FullDevStudio — test-failure analysis for commit 91e7650.

Scope CI failures Commit 91e7650


🧪 CI Analysis — click to expand
📊 maui-pr

No failures found.


🧪 maui-pr-devicetests
  • 🟡 Needs human investigation - Android Mono ImageWithUndefinedSizeAndWithBackgroundSetRenders: red missing; the main match lacks runtime identification, so verify equivalent Mono results.
  • 🟡 Needs human investigation - Android Mono Controls crash: incomplete execution; inspect the crash stack separately from the image assertion.
  • 🟡 Needs human investigation - MacCatalyst Mono, macOS 26: Core and Controls both timed out after 3600s without results; inspect launch logs, since target history lacks equivalent diagnostics.

🧪 maui-pr-uitests

🧭 Follow-up — actions and refresh

Next action: Compare unresolved failures with identical runtime/simulator setups; restore complete timeout diagnostics and results.

Maintainers: comment /review tests to refresh this report.

@github-actions github-actions Bot added s/agent-review-in-progress AI review is currently running for this PR and removed s/agent-review-in-progress AI review is currently running for this PR labels Oct 23, 2026
@MauiBot

MauiBot commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

PR Test Gate

@FullDevStudio — existing-test verification for commit 91e7650f.

Result PASSED Platform Android Commit 91e7650f


🧪 Gate analysis — click to expand

✅ Passed. The selected verification satisfied the gate's passing conditions. Unmatched, skipped, or inconclusive groups are not passing evidence.

🧪 Unit tests
Test group Without fix With fix
ContentViewUnitTests ✅ Failed as expected (107s) ✅ Passed (28s)
Execution log excerpts

Without fix ContentViewUnitTests

     at Microsoft.Maui.Controls.Core.UnitTests.ContentViewUnitTests.HiddenContentTakesNoSpace() in /_/src/Controls/tests/Core.UnitTests/ContentViewUnitTest.cs:line 144
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

With fix ContentViewUnitTests

rosoft.Maui.Controls.Core.UnitTests
  Passed TestFrameLayout [225 ms]
  Passed LayoutHorizontallyCenter [14 ms]
  Passed TestSetChild [15 ms]
  Passed NonTemplatedContentInheritsBindingContext [9 ms]
  Passed TestReplaceChild [3 ms]
  Passed HeightRequest [1 ms]
  Passed HiddenContentTakesNoSpace [4 ms]
  Passed DoesInheritBindingContextToTemplate [61 ms]
  Passed WidthRequest [1 ms]
  Passed PacksContent [20 ms]
  Passed ContentDoesGetBindingContext [< 1 ms]
  Passed DoesNotInheritBindingContextToContentFromControlTemplate [3 ms]
  Passed LayoutVerticallyEnd [2 ms]
  Passed LayoutVerticallyBegin [1 ms]
  Passed LayoutHorizontallyBegin [1 ms]
  Passed ContentParentIsNotInsideTemplate [< 1 ms]
  Passed LayoutHorizontallyEnd [1 ms]
  Passed BindingContextNotLostWhenSwitchingTemplates [2 ms]
[xUnit.net 00:00:03.95]   Finished:    Microsoft.Maui.Controls.Core.UnitTests
  Passed TemplateInflates [< 1 ms]
  Passed ContentView_should_have_the_InternalChildren_correctly_when_Content_changed [3 ms]
  Passed TestConstructor [3 ms]
  Passed NullTemplateDirectlyHosts [< 1 ms]
  Passed LayoutVerticallyCenter [2 ms]
Test Run Successful.
Total tests: 23
     Passed: 23
 Total time: 4.9453 Seconds

PR head: 91e7650f.

Without-fix baseline: 74cf8e3c.

@MauiBot MauiBot added s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) and removed s/agent-review-in-progress AI review is currently running for this PR labels Oct 23, 2026
@kubaflo

kubaflo commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

I compared this with MAUI's other layout paths and the native platform contracts at 91e7650f.

Conclusion: this fixes a real MAUI layout inconsistency, rather than removing intentionally supported behavior. A collapsed child should stop contributing its desired size to a content-sized parent. That does not mean its still-visible parent must disappear.

MAUI contract and comparable components

The layout design explicitly distinguishes Hidden from Collapsed: Hidden reserves space; Collapsed does not. IsVisible=false maps to Collapsed. The public IsVisible documentation in source makes the same promise.

Checking specifically Visibility.Collapsed, rather than requiring Visibility.Visible, is the right distinction.

Native platform behavior

Platform Relevant native behavior
Android A direct View.measure() does not automatically return zero because the view is GONE. Ordinary parents implement the exclusion: ViewGroup.measureChildren() skips GONE, and FrameLayout.onMeasure() excludes it by default. MAUI's content-measuring parent needs the equivalent check.
Windows / WinUI Visibility.Collapsed does not communicate a desired size to layout. This explains why the reported case can already work on Windows; the shared MAUI parent should not depend on a native measurement side effect.
iOS / MacCatalyst A plain UIView.isHidden still participates in autoresizing; it is not a universal layout-collapse operation. UIStackView specifically excludes hidden arranged views from its layout. MAUI likewise distinguishes hidden from collapsed and adds a collapse constraint. Raw UIKit hiding semantics are not grounds for preserving a collapsed child's MAUI desired size.

Important limits

The wrapper retains its own layout requirements. Padding, Border stroke, explicit/minimum dimensions, and space allocated by a parent layout can remain. Consequently, Padding=10 with collapsed content correctly measures to 20 x 20 in the new test, not zero. Hide the wrapper itself when the entire card, including its decoration and parent-layout participation, should disappear. Measuring PresentedContent also correctly respects templates: hiding an inner content view should not automatically remove visible template chrome.

There is some reach beyond the title: the internal overload is used by Android ScrollView. Conversely, iOS/MacCatalyst ScrollView has a separate private MeasureContent, so this PR should not be interpreted as covering every ScrollView path.

The existing test gate reports the new regression test failing without the fix and all 23 ContentViewUnitTests passing with it. Useful additional coverage would be Visibility.Hidden retaining space, Border padding/stroke, child margins versus wrapper sizing, a visible -> collapsed -> visible round-trip, and the Android ScrollView overload. My native comparison here is documentation/source analysis, not a fresh device run.

@kubaflo
kubaflo changed the base branch from main to inflight/current October 23, 2026 17:17
This was referenced Nov 17, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 23, 2026

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — 91e7650f Deployed Oct 22, 2026 by FullDevStudio via conclusion #2460
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community ✨ Community Contribution s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants