Skip to content

[Android] Fix ImageButton not rendering when CornerRadius is larger than half its size - #39344

Merged
kubaflo merged 4 commits into
dotnet:inflight/currentfrom
KirkPatrickJunsay:fix/imagebutton-oversized-corner-radius
Oct 15, 2026
Merged

kubaflo merged 4 commits into
dotnet:inflight/currentfrom
KirkPatrickJunsay:fix/imagebutton-oversized-corner-radius

Conversation

@KirkPatrickJunsay

@KirkPatrickJunsay KirkPatrickJunsay commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

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 from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

On Android, an ImageButton whose CornerRadius is much larger than half of its size does not draw its background. It still takes up space and still receives taps.

Root cause

#30074 made UpdateMauiRippleDrawableStroke copy the corner radius into the ShapeAppearanceModel of the ShapeableImageView, so that the image is clipped to the rounded corners. ShapeableImageView erases everything outside that shape, background included. The model takes the radius as an absolute size and does not limit it to the size of the view, while the GradientDrawable layers that draw the background do. With a radius of 100 on a 50x50 view, the whole view is erased.

Fix

  • UpdateMauiRippleDrawableStroke limits the radius it gives to the ShapeAppearanceModel to half of the shorter side of the view. The drawables keep the radius they had.
  • The view has no size when the mapper first runs, so ImageButtonHandler.OnPlatformViewLayoutChange now also runs the CornerRadius mapping with UpdateValue(nameof(IImageButton.CornerRadius)) when the view's size changes, so custom mappings are applied there too. A change of position only does not re-run it. It already calls UpdateBackground there.
  • Before the first layout the radius is passed through unchanged, as it is today.

A radius of half the size or less gives the same model as before. No public API changes.

I tried Material's ClampedCornerSize first. The binding marks it as internal API (XAOBS001), so the limit is applied in MAUI.

Tests

ImageButtonHandlerTests.BackgroundRendersWhenCornerRadiusIsLargerThanHalfTheSize (Core.DeviceTests, Android) creates an ImageButton with a red background and CornerRadius = 100, and checks that red is drawn.

Without fix With fix
New test Fails: Color [A=255, R=255, G=0, B=0] not found Passes
Core.DeviceTests Category=ImageButton 150 passed, 1 failed 151 passed, 0 failed
Core.DeviceTests Category=Button not run 114 passed, 0 failed

Run on main (55c1377) on a Lenovo TB323FU tablet, Android 16 (API 36). The new test also fails when only the OnPlatformViewLayoutChange change is removed.

ImageButtonHandlerTests.CustomCornerRadiusMappingIsKeptAfterLayout overrides the CornerRadius mapping to square the corners and checks they are still square after layout. It fails when the layout callback calls UpdateCornerRadius directly (corner size 69 instead of 0) and passes with UpdateValue; Category=ImageButton is then 152 passed, 0 failed.

ImageButtonHandlerTests.CornerRadiusMappingIsReappliedOnlyWhenTheSizeChanges moves the laid-out button without resizing it and checks the CornerRadius mapping did not run again, then resizes it and checks it did. It fails without the size check (the mapping runs on the move) and passes with it; Category=ImageButton is 153 passed, 0 failed.

The Android snapshot for CornerRadiusShouldBeApplied (Issue23854) is updated. Its 100x20 ImageButton with CornerRadius="20" was clipped to a distorted shape and is now a pill. The new image is the one this PR's CI produced.

I ran the XAML from the issue in the Sandbox app on the same tablet (videos below). I did not run the UI tests locally, and I did not test with Material 3 enabled.

Before
https://github.com/user-attachments/assets/c02d1e2a-4569-4aee-8b40-b2c115d3f1f9

After
https://github.com/user-attachments/assets/56d0967f-26c6-4bf0-8cd3-5121f05d1bb5

Issues Fixed

Fixes #39307

…han half its size

The corner radius was copied into the ShapeAppearanceModel without a
limit, and ShapeableImageView erased the whole view when the radius was
much larger than the view. The radius given to the model is now limited
to half of the shorter side and is applied again when the view is laid
out.
@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 -- 39344

Or

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

@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 12, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @@KirkPatrickJunsay! 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 @KirkPatrickJunsay! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@KirkPatrickJunsay

Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service agree

github-actions[bot]

This comment was marked as outdated.

@kubaflo

This comment has been minimized.

1 similar comment
@kubaflo

This comment has been minimized.

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

Copy link
Copy Markdown
Contributor

Note

🔍 /review gate started

AzDO build 15668456 is running for android.

The s/agent-review-in-progress label stays on this PR while existing PR tests are verified. The final gate report contains test evidence only: no expert review, alternative fixes, or Deep UI sweep runs.

@github-actions

Copy link
Copy Markdown
Contributor

Note

🔍 /review gate skipped — a review is already running

This PR already holds the s/agent-review-in-progress lock, so a new run was not started. The in-flight review or gate must finish first.

Re-comment /review gate once it completes to start a fresh run.

🔍 Automated message from the .NET MAUI PR test gate.

@MauiBot

This comment has been minimized.

@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 13, 2026
github-actions[bot]

This comment was marked as outdated.

@kubaflo

This comment has been minimized.

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

Copy link
Copy Markdown
Contributor

Note

🔍 /review started

AzDO build 15682287 is running for android.

The s/agent-review-in-progress label stays on this PR through the full pipeline. The final AI Summary and outcome labels are posted only after Gate, expert review, and Deep UI tests finish.

github-actions[bot]

This comment was marked as outdated.

This was referenced Nov 12, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community ✨ Community Contribution s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] ImageButton does not render its background when CornerRadius is larger than half of its size (regression in .NET 10)

3 participants