fix(Android): Restrict CommandBar content width to prevent primary commands overflow #21662
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
On Android, when a
CommandBarcontains long content (such as aTextBlockwith a lengthy title), the content was not width-constrained. This caused the content to expand indefinitely, pushing primary command buttons off-screen and making them inaccessible to users.Before:

After:

Root Cause
The
_contentContainer(aBorderelement) inCommandBarRenderer.Android.cswas created withHorizontalAlignment.Leftto properly measure based on child content size, but it lacked aMaxWidthconstraint. This allowed content to grow without bounds within the native AndroidToolbar, causing layout overflow.Solution
Implemented dynamic content width constraint by:
Added
ToolbarLayoutListener- Monitors the nativeToolbarfor layout changes (rotation, resize, menu updates)Added
UpdateContentMaxWidth()- Calculates available space for content by accounting for:Automatic recalculation - MaxWidth is updated whenever:
This ensures the content is properly constrained while preserving the existing
TextTrimmingbehavior (ellipsis) onTextBlockelements.Testing
When_CommandBar_Has_Long_Content_Then_PrimaryCommands_Remain_Visible()that verifies:CommandBar_LongTitle.xaml,CommandBar_With_Long_Sentences.xaml) can be used for manual verificationFixes
Closes #21654
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
aka.mscurl -I -sSL --retry 5 --retry-delay 2 --connect-timeout 15 REDACTED(dns block)crl.godaddy.comdotnet restore Uno.UI/Uno.UI.netcoremobile.csproj(dns block)ocsp.godaddy.comdotnet restore Uno.UI/Uno.UI.netcoremobile.csproj(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Fixes #21654
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.