Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 22, 2025

Problem

On Android, when a CommandBar contains long content (such as a TextBlock with 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:
image

After:
image

Root Cause

The _contentContainer (a Border element) in CommandBarRenderer.Android.cs was created with HorizontalAlignment.Left to properly measure based on child content size, but it lacked a MaxWidth constraint. This allowed content to grow without bounds within the native Android Toolbar, causing layout overflow.

Solution

Implemented dynamic content width constraint by:

  1. Added ToolbarLayoutListener - Monitors the native Toolbar for layout changes (rotation, resize, menu updates)

  2. Added UpdateContentMaxWidth() - Calculates available space for content by accounting for:

    • Navigation icon (back button): ~56dp when present
    • Primary command buttons: ~48dp each
    • Toolbar padding: ~32dp total
    • Converts physical pixels to logical pixels for proper XAML sizing
  3. Automatic recalculation - MaxWidth is updated whenever:

    • The toolbar layout changes
    • Primary or secondary commands are updated
    • Navigation elements are added/removed

This ensures the content is properly constrained while preserving the existing TextTrimming behavior (ellipsis) on TextBlock elements.

Testing

  • Added runtime test When_CommandBar_Has_Long_Content_Then_PrimaryCommands_Remain_Visible() that verifies:
    • Content MaxWidth is set and reasonable
    • Content doesn't exceed toolbar bounds
    • Primary commands remain visible within screen bounds
  • Existing samples (CommandBar_LongTitle.xaml, CommandBar_With_Long_Sentences.xaml) can be used for manual verification

Fixes

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.ms
    • Triggering command: curl -I -sSL --retry 5 --retry-delay 2 --connect-timeout 15 REDACTED (dns block)
  • crl.godaddy.com
    • Triggering command: dotnet restore Uno.UI/Uno.UI.netcoremobile.csproj (dns block)
  • ocsp.godaddy.com
    • Triggering command: dotnet 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

This section details on the original issue you should resolve

<issue_title>Android Native command bar content width not restricted, pushing primary commands out of screen bounds</issue_title>
<issue_description>### Current behavior 🐛

Command bar is based NativeDefaultCommandBar. Content is a text block. When content text is long, it pushes the primary commands out of screen bounds

Image

Expected behavior 🎯

The content is cut off and ... added when width is beyond available space, without pushing the back button or primary commands out of bounds

Image

How to reproduce it (as minimally and precisely as possible) 🔬

CommandBar.zip

Simply create a command bar with a long text block.

Workaround 🛠️

No response

Renderer 🎨

  • Skia
  • Native

Affected platforms 📱💻🖥️

Android

Uno.Sdk version (and other relevant versions) 📦

No response

IDE version 🧑‍💻

No response

Anything else we need to know? 💬

No response</issue_description>

Comments on the Issue (you are @copilot in this section)

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.

Copilot AI and others added 2 commits October 22, 2025 03:39
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI changed the title [WIP] Fix command bar content width issue fix(Android): Restrict CommandBar content width to prevent primary commands overflow Oct 22, 2025
Copilot AI requested a review from MartinZikmund October 22, 2025 03:53
Copilot finished work on behalf of MartinZikmund October 22, 2025 03:53
@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21662/docs/index.html

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.

Android Native command bar content width not restricted, pushing primary commands out of screen bounds

4 participants