Repository navigation
Add badge support to TabbedPage - #37755
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: c8d637eb-47e2-40ed-8fc8-51bb77a05ce9
…is-add-tabbedpage-badges
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 37755Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 37755" |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
This comment has been minimized.
This comment has been minimized.
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 7 findings
See inline comments for details.
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
This PR adds badge support for regular TabbedPage children using a Shell-aligned attached-property model (BadgeText, BadgeColor, BadgeTextColor), with platform-specific implementations and coverage via unit/device tests plus a sample page.
Changes:
- Introduces new
TabbedPageattached bindable properties for badge text/background/text-color and wires property-change propagation for efficient updates. - Implements native badge mapping across Android (Material top/bottom tabs + overflow rules), iOS/Mac Catalyst (
UITabBarItem), and Windows (InfoBadgeviaNavigationViewItemViewModel). - Adds tests (Core unit tests + Android/iOS device tests) and a Controls.Sample page to exercise badge scenarios interactively.
Show a summary per file
| File | Description |
|---|---|
| src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.iOS.cs | Adds iOS device coverage for badge value/color/text-color updates and resets. |
| src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Android.cs | Adds Android device coverage for badge updates, overflow behavior, and tab insertion behavior. |
| src/Controls/tests/Core.UnitTests/TabbedPageBadgeTests.cs | Adds unit tests validating attached-property defaults, change notification, and binding support. |
| src/Controls/src/Core/TabbedPage/TabbedPage.Windows.cs | Maps attached badge properties onto Windows tab item view models. |
| src/Controls/src/Core/TabbedPage/TabbedPage.iOS.cs | Updates UITabBarItem badge value/color/text attributes on initial set and on property changes. |
| src/Controls/src/Core/TabbedPage/TabbedPage.cs | Defines the public attached properties + accessors and wires page PropertyChanged handling for badge changes. |
| src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt | Declares new public API surface for the attached badge properties (netstandard). |
| src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt | Declares new public API surface for the attached badge properties (net). |
| src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt | Declares new public API surface for the attached badge properties (net-windows). |
| src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt | Declares new public API surface for the attached badge properties (net-tizen). |
| src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt | Declares new public API surface for the attached badge properties (net-maccatalyst). |
| src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt | Declares new public API surface for the attached badge properties (net-ios). |
| src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt | Declares new public API surface for the attached badge properties (net-android). |
| src/Controls/src/Core/Platform/Windows/TabbedPage/TabbedPageStyle.xaml | Ensures null badge brushes don’t override theme defaults by converting null → UnsetValue. |
| src/Controls/src/Core/Platform/Windows/NullToUnsetValueConverter.cs | Adds a WinUI converter to preserve native defaults when badge colors are unset. |
| src/Controls/samples/Controls.Sample/ViewModels/CompatibilityViewModel.cs | Registers the new TabbedPage badges sample entry in the Compatibility gallery. |
| src/Controls/samples/Controls.Sample/Pages/Compatibility/TabbedPageBadgePage.cs | Adds an interactive sample page demonstrating numeric/text/dot badges and runtime updates. |
Review details
Suppressed comments (1)
src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Android.cs:85
- The removal assertion can also throw NullReferenceException for top tabs if GetTabAt(0) returns null; using GetBadge() keeps the check null-safe and consistent with the rest of the test.
await AssertEventually(() => bottomTabs
? tabbedPage.TabbedPageManager.BottomNavigationView.GetBadge(0) is null
: tabbedPage.TabbedPageManager.TabLayout.GetTabAt(0).Badge is null,
message: "Badge was not removed.");
- Files reviewed: 18/18 changed files
- Comments generated: 1
- Review effort level: Lite
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: c8d637eb-47e2-40ed-8fc8-51bb77a05ce9
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 3 findings
See inline comments for details.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: c8d637eb-47e2-40ed-8fc8-51bb77a05ce9
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Windows.cs:132
- The assertions that the initial badge background/foreground are not Blue/Yellow can make this test flaky because InfoBadge default colors can vary with the OS/theme (and may legitimately match these chosen colors). The later assertions already validate that setting badge colors updates the UI and that clearing them restores the captured defaults, so these NotEqual checks are redundant.
var defaultBackgroundColor = Assert.IsType<WSolidColorBrush>(infoBadge.Background).Color;
var defaultForegroundColor = Assert.IsType<WSolidColorBrush>(infoBadge.Foreground).Color;
Assert.NotEqual(Colors.Blue.ToWindowsColor(), defaultBackgroundColor);
Assert.NotEqual(Colors.Yellow.ToWindowsColor(), defaultForegroundColor);
- Files reviewed: 19/19 changed files
- Comments generated: 0 new
- Review effort level: Lite
This comment has been minimized.
This comment has been minimized.
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 4 findings
See inline comments for details.
| if (hasOverflow) | ||
| { | ||
| // SetupMenu uses each child index as its menu item ID; Material badge APIs take IDs, not positions. | ||
| bottomNavigationView.RemoveBadge(maxItems - 1); |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[moderate] Logic and Correctness — RemoveBadge(maxItems - 1) cannot clear the overflow slot because no menu item with that ID exists once the bar is in overflow. BottomNavigationViewUtils.SetupMenu only creates real items with IDs 0..maxBottomItems-2 when showMore is true, and adds the overflow item with MoreTabId (BottomNavigationViewUtils.cs:145-153, MoreTabId = 99 at line 28). NavigationBarView.RemoveBadge(int) keys on menu item ID, not tab position, so this call is a guaranteed no-op — the ID maxItems - 1 (4) is exactly the item SetupMenu deletes when it switches to overflow. If the intent is to clear a badge on the "More" tab, the argument must be BottomNavigationViewUtils.MoreTabId; if the intent is to clear the stale trailing slot, the RemoveBadgePageMappings(_bottomBadgePages, lastIndexToUpdate + 1, ...) call three lines below already covers index maxItems - 1, making this line dead.
|
|
||
| var badgeColor = TabbedPage.GetBadgeColor(page); | ||
| var badgeTextColor = TabbedPage.GetBadgeTextColor(page); | ||
| if ((propertyName == TabbedPage.BadgeColorProperty.PropertyName && badgeColor is null) || |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[moderate] Handler Mapper and Property Patterns — The remove-and-recreate reset that restores the platform-default badge color is gated on propertyName, so UpdateBottomBadge is not idempotent: it cannot return an already-colored badge to the default. propertyName is null on every full-refresh call from UpdateAllBadges (line 385), and it is also lost on the deferred recovery path — when UpdateBadge/UpdateBottomBadge finds BottomNavigationView null it calls ScheduleBadgeUpdate() and drops the property name, so the later TryUpdateAllBadges → UpdateBottomBadge(page, i) runs with propertyName == null. Concrete scenario: a badge is created with BadgeColor = Red while the view is attached, the TabbedPage is detached (Shell tab switch / re-parenting), SetBadgeColor(page, null) is applied during that window, and the deferred refresh then calls GetOrCreateBadge(index) on the surviving drawable without ever clearing BackgroundColor — the badge stays red. The Shell equivalent (ShellItemHandler.Android.cs:565-569) avoids this by removing whenever badgeColor is null, independent of which property changed.
|
|
||
| var badgeColor = TabbedPage.GetBadgeColor(page); | ||
| var badgeTextColor = TabbedPage.GetBadgeTextColor(page); | ||
| if ((propertyName == TabbedPage.BadgeColorProperty.PropertyName && badgeColor is null) || |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[moderate] Handler Mapper and Property Patterns — Same non-idempotent color reset as the bottom path: tab.RemoveBadge() only runs when propertyName names the color property being cleared. UpdateTopBadge is called with propertyName == null from UpdateAllBadges (line 411) and from the deferred ScheduleBadgeUpdate() recovery at line 502 (which discards the property name when TabLayout?.GetTabAt(index) is null). A BadgeColor/BadgeTextColor clear that arrives while the TabLayout tab is unavailable — e.g. before SetTabLayout() has attached tabs, or while the page is off the navigation stack — is replayed with propertyName == null, so tab.OrCreateBadge returns the existing drawable and the stale color persists. Gate on badgeColor is null / badgeTextColor is null alone (matching ShellItemHandler.Android.cs:565-569) so any refresh fully reconstructs the badge state.
|
|
||
| Assert.Null(bottomNavigationView.GetBadge(4)); | ||
| Assert.Null(bottomNavigationView.GetBadge(5)); | ||
| Assert.Null(bottomNavigationView.GetBadge(BottomNavigationViewUtils.MoreTabId)); |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[moderate] Regression Prevention and Test Coverage — These three assertions cannot discriminate and do not cover the overflow branch they appear to target. Nothing in the implementation ever calls GetOrCreateBadge(MoreTabId), so line 226 passes unconditionally. Lines 224-225 are also trivially true: with 6 children the bar is in overflow, so SetupMenu never creates menu items with IDs 4 or 5 (BottomNavigationViewUtils.cs:106-153) and GetBadge returns null regardless of UpdateAllBadges. The scenario that actually exercises hasOverflow/lastIndexToUpdate and RemoveBadge(maxItems - 1) in TabbedPageManager.cs:378-397 is the transition: start with 5 badged children (no overflow, badge present on index 4), then add a 6th child and assert the index-4 badge is gone while indices 0-3 keep theirs. Without that case, the overflow clearing logic — including the incorrect ID at line 391 — is untested.
MauiBot
left a comment
There was a problem hiding this comment.
AI Review Summary
@jfversluis — new AI review results are available based on commit
2fd4b03.
🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix
Gate Result: ✅ PASSED
Platform: ANDROID · Base: net11.0 · Merge base: cbb52ef0
✅ Verified (new API / feature) — this PR adds new API and a test that references it in the same project, so reverting the fix un-compiles the test: there is no valid "fails without the fix" baseline to establish (a compile-coupled baseline). The gate instead verified the fix by a clean build + pass with the fix, so this is a real PASS rather than a non-committal INCONCLUSIVE.
| Test | Without Fix (expect FAIL) | With Fix (expect PASS) |
|---|---|---|
🧪 TabbedPageBadgeTests TabbedPageBadgeTests |
🛠️ BUILD ERROR | ✅ PASS — 69s |
📱 TabbedPageTests (BadgePropertiesUpdateNativeTab, BottomBadgeUpdateCompletesWithNoPages, BadgeTextUpdateDoesNotRecreateDefaultColoredBadge, BadgeColorsDoNotTransferWhenTabIndexIsReused, BottomBadgeColorsDoNotTransferWhenTrailingIndexIsReused, BottomTabBadgesRespectOverflow, BadgeFollowsPageWhenTabIndexChanges) Category=TabbedPage |
🛠️ BUILD ERROR | ✅ PASS — 410s |
🔴 Without fix — 🧪 TabbedPageBadgeTests: 🛠️ BUILD ERROR · 100s
Error-relevant lines (filtered from the build log):
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/TabbedPageBadgeTests.cs(93,27): error CS0117: 'TabbedPage' does not contain a definition for 'BadgeTextColorProperty' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/TabbedPageBadgeTests.cs(100,31): error CS0117: 'TabbedPage' does not contain a definition for 'BadgeTextProperty' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/TabbedPageBadgeTests.cs(101,31): error CS0117: 'TabbedPage' does not contain a definition for 'BadgeColorProperty' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/TabbedPageBadgeTests.cs(102,31): error CS0117: 'TabbedPage' does not contain a definition for 'BadgeTextColorProperty' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/TabbedPageBadgeTests.cs(111,34): error CS0117: 'TabbedPage' does not contain a definition for 'GetBadgeText' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/TabbedPageBadgeTests.cs(112,43): error CS0117: 'TabbedPage' does not contain a definition for 'GetBadgeColor' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/TabbedPageBadgeTests.cs(113,42): error CS0117: 'TabbedPage' does not contain a definition for 'GetBadgeTextColor' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/TabbedPageBadgeTests.cs(122,15): error CS0117: 'TabbedPage' does not contain a definition for 'SetBadgeText' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/TabbedPageBadgeTests.cs(123,15): error CS0117: 'TabbedPage' does not contain a definition for 'SetBadgeColor' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/TabbedPageBadgeTests.cs(124,15): error CS0117: 'TabbedPage' does not contain a definition for 'SetBadgeText' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/TabbedPageBadgeTests.cs(125,15): error CS0117: 'TabbedPage' does not contain a definition for 'SetBadgeColor' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/TabbedPageBadgeTests.cs(127,33): error CS0117: 'TabbedPage' does not contain a definition for 'GetBadgeText' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/TabbedPageBadgeTests.cs(128,40): error CS0117: 'TabbedPage' does not contain a definition for 'GetBadgeColor' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/TabbedPageBadgeTests.cs(129,35): error CS0117: 'TabbedPage' does not contain a definition for 'GetBadgeText' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/TabbedPageBadgeTests.cs(130,41): error CS0117: 'TabbedPage' does not contain a definition for 'GetBadgeColor' [/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj]
🟢 With fix — 🧪 TabbedPageBadgeTests: PASS ✅ · 69s
(no coded error found; showing last 1200 chars)
/vsts/work/1/s/artifacts/bin/Controls.Core.UnitTests/Debug/net11.0/Microsoft.Maui.Controls.Core.UnitTests.dll (.NETCoreApp,Version=v11.0)
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 11.0.0-rc.1.26379.102)
[xUnit.net 00:00:00.18] Discovering: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:01.36] Discovered: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:01.37] Starting: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:01.46] Finished: Microsoft.Maui.Controls.Core.UnitTests
Passed BadgePropertiesDefaultToNull [6 ms]
Passed BadgePropertyChangeFires(propertyName: "BadgeColor") [2 ms]
Passed BadgePropertyChangeFires(propertyName: "BadgeTextColor") [< 1 ms]
Passed BadgePropertyChangeFires(propertyName: "BadgeText") [< 1 ms]
Passed BadgePropertiesSupportDataBinding [26 ms]
Passed EmptyBadgeTextIsDistinctFromNull [< 1 ms]
Passed BadgePropertiesCanBeSetAndCleared [< 1 ms]
Passed BadgePropertiesHaveCorrectMetadata [< 1 ms]
Passed PagesCanHaveIndependentBadges [< 1 ms]
Test Run Successful.
Total tests: 9
Passed: 9
Total time: 1.9385 Seconds
🔴 Without fix — 📱 TabbedPageTests (BadgePropertiesUpdateNativeTab, BottomBadgeUpdateCompletesWithNoPages, BadgeTextUpdateDoesNotRecreateDefaultColoredBadge, BadgeColorsDoNotTransferWhenTabIndexIsReused, BottomBadgeColorsDoNotTransferWhenTrailingIndexIsReused, BottomTabBadgesRespectOverflow, BadgeFollowsPageWhenTabIndexChanges): 🛠️ BUILD ERROR · 186s
Error-relevant lines (filtered from the build log):
/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Android.cs(113,15): error CS0117: 'TabbedPage' does not contain a definition for 'SetBadgeText' [/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj::TargetFramework=net11.0-android]
/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Android.cs(125,16): error CS0117: 'TabbedPage' does not contain a definition for 'SetBadgeText' [/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj::TargetFramework=net11.0-android]
/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Android.cs(140,15): error CS0117: 'TabbedPage' does not contain a definition for 'SetBadgeText' [/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj::TargetFramework=net11.0-android]
/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Android.cs(141,15): error CS0117: 'TabbedPage' does not contain a definition for 'SetBadgeColor' [/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj::TargetFramework=net11.0-android]
/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Android.cs(142,15): error CS0117: 'TabbedPage' does not contain a definition for 'SetBadgeTextColor' [/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj::TargetFramework=net11.0-android]
/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Android.cs(144,15): error CS0117: 'TabbedPage' does not contain a definition for 'SetBadgeText' [/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj::TargetFramework=net11.0-android]
/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Android.cs(173,15): error CS0117: 'TabbedPage' does not contain a definition for 'SetBadgeText' [/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj::TargetFramework=net11.0-android]
/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Android.cs(174,15): error CS0117: 'TabbedPage' does not contain a definition for 'SetBadgeColor' [/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj::TargetFramework=net11.0-android]
/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Android.cs(175,15): error CS0117: 'TabbedPage' does not contain a definition for 'SetBadgeTextColor' [/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj::TargetFramework=net11.0-android]
/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Android.cs(189,16): error CS0117: 'TabbedPage' does not contain a definition for 'SetBadgeText' [/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj::TargetFramework=net11.0-android]
/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Android.cs(209,17): error CS0117: 'TabbedPage' does not contain a definition for 'SetBadgeText' [/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj::TargetFramework=net11.0-android]
/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Android.cs(239,15): error CS0117: 'TabbedPage' does not contain a definition for 'SetBadgeText' [/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj::TargetFramework=net11.0-android]
Build FAILED.
🟢 With fix — 📱 TabbedPageTests (BadgePropertiesUpdateNativeTab, BottomBadgeUpdateCompletesWithNoPages, BadgeTextUpdateDoesNotRecreateDefaultColoredBadge, BadgeColorsDoNotTransferWhenTabIndexIsReused, BottomBadgeColorsDoNotTransferWhenTrailingIndexIsReused, BottomTabBadgesRespectOverflow, BadgeFollowsPageWhenTabIndexChanges): PASS ✅ · 410s
(no coded error found; showing last 1200 chars)
"totalMemoryBytes": 8322994176
},
"target": {
"kind": "emulator",
"name": "sdk_gphone_x86_64",
"identifier": "emulator-5554",
"operatingSystem": "Android",
"operatingSystemVersion": "11",
"apiLevel": 30,
"architecture": "x86_64",
"supportedArchitectures": [
"x86_64",
"x86",
"arm64-v8a",
"armeabi-v7a",
"armeabi"
],
"manufacturer": "Google",
"model": "sdk_gphone_x86_64",
"productName": "sdk_gphone_x86_64",
"buildFingerprint": "google/sdk_gphone_x86_64/generic_x86_64_arm64:11/RSR1.201211.001/7027799:user/release-keys",
"cpuModel": "0",
"cpuMaxFrequencyHertz": 2000,
"totalMemoryBytes": 2077544448
}
}
}
<<XHARNESS_RESULT_END>>
info: Attempting to remove apk 'com.microsoft.maui.controls.devicetests'..
info: Successfully uninstalled com.microsoft.maui.controls.devicetests
XHarness exit code: 0
Passed: 11
Failed: 0
Skipped: 0
Total: 11
Tests completed successfully
⚠️ Failure Details
- 🛠️ TabbedPageBadgeTests without fix: build failed before tests could run
/home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/TabbedPageBadgeTests.cs(13,27): error CS0117: 'TabbedPage' does not contain a definition for 'GetBadgeText' [/home/vsts/work/1/s/src/Controls/test...
- 🛠️ TabbedPageTests (BadgePropertiesUpdateNativeTab, BottomBadgeUpdateCompletesWithNoPages, BadgeTextUpdateDoesNotRecreateDefaultColoredBadge, BadgeColorsDoNotTransferWhenTabIndexIsReused, BottomBadgeColorsDoNotTransferWhenTrailingIndexIsReused, BottomTabBadgesRespectOverflow, BadgeFollowsPageWhenTabIndexChanges) without fix: build failed before tests could run
/home/vsts/work/1/s/src/Controls/tests/DeviceTests/Elements/TabbedPage/TabbedPageTests.Android.cs(44,15): error CS0117: 'TabbedPage' does not contain a definition for 'SetBadgeText' [/home/vsts/work/1...
📁 Fix files reverted (13 files)
src/Controls/samples/Controls.Sample/ViewModels/CompatibilityViewModel.cssrc/Controls/src/Core/Platform/Android/TabbedPageManager.cssrc/Controls/src/Core/Platform/Windows/TabbedPage/TabbedPageStyle.xamlsrc/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txtsrc/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txtsrc/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txtsrc/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txtsrc/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txtsrc/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txtsrc/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txtsrc/Controls/src/Core/TabbedPage/TabbedPage.Windows.cssrc/Controls/src/Core/TabbedPage/TabbedPage.cssrc/Controls/src/Core/TabbedPage/TabbedPage.iOS.cs
New files (not reverted):
src/Controls/samples/Controls.Sample/Pages/Compatibility/TabbedPageBadgePage.cssrc/Controls/src/Core/Platform/Windows/NullToUnsetValueConverter.cs
📋 Pre-Flight — Context & Validation
PR #37755 Pre-Flight
Scope
- Title: Add badge support to TabbedPage
- Base / head:
net11.0(78502a53) /jfversluis-add-tabbedpage-badges(2fd4b039) - Local review commit:
3f134d4e(PR #37755 squashed for review) - Platform for STEP 5a: Android
- Change size: 19 files, 1,152 additions, 7 deletions
The PR adds TabbedPage.BadgeText, BadgeColor, and BadgeTextColor attached properties and maps them to native badges on Android, Apple platforms, and Windows. Android support is implemented in TabbedPageManager: it schedules badge application after tab creation/layout, handles top and bottom tabs, treats an empty string as a dot, removes badges for null, resets native defaults when a color is cleared, tracks page-to-index mappings so colors do not leak when indices are reused, and preserves the five-item overflow behavior.
Direct Diff Assessment
The Android implementation adds two page-index dictionaries plus a deferred _badgesNeedUpdate path. OnPagePropertyChanged routes badge property changes to targeted updates, while collection changes schedule a complete refresh. UpdateAllBadges separately handles Material BottomNavigationView and TabLayout, including overflow and empty-child cases. The shared API is added in TabbedPage.cs; platform implementations consume that attached-property state.
The PR also adds public API entries for every applicable target framework, platform-specific Apple/Windows implementations, managed tests, Android/Apple/Windows device tests, and a sample. No linked issue is declared.
Existing Approach and Risks to Avoid
- Do not repeat the PR's dictionary-based page/index tracking plus layout-posted full refresh as merely a relocated variant.
- Preserve native default badge colors when attached colors are unset.
- Do not recreate the native
BadgeDrawableon ordinary text-only updates; recreate only when clearing a previously applied custom color or replacing the page occupying an index. - Do not transfer custom colors when a tab index is reused.
- Keep bottom-navigation overflow badges off the More item and hidden pages.
- Keep all Android native view work on the UI thread and tolerate tab views not yet being materialized.
Gate Evidence (Read-Only)
The prior gate is authoritative and was not rerun. It passed:
- Managed primary test:
TabbedPageBadgeTests— 9/9 passed with the PR. - Mandatory Android regression surface:
Category=TabbedPage— all tests passed, including:
BadgePropertiesUpdateNativeTab,BottomBadgeUpdateCompletesWithNoPages,
BadgeTextUpdateDoesNotRecreateDefaultColoredBadge,
BadgeColorsDoNotTransferWhenTabIndexIsReused,
BottomBadgeColorsDoNotTransferWhenTrailingIndexIsReused,
BottomTabBadgesRespectOverflow, andBadgeFollowsPageWhenTabIndexChanges.
Allowed narrow commands for a candidate that reaches testing:
dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter "FullyQualifiedName~TabbedPageBadgeTests"
pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Controls -Platform android -TestFilter "Category=TabbedPage"No full suite is permitted.
Baseline Safety Constraint
EstablishBrokenBaseline.ps1 detects 15 non-test fix files. Thirteen existed at the merge base, while these two production files are new:
src/Controls/samples/Controls.Sample/Pages/Compatibility/TabbedPageBadgePage.cssrc/Controls/src/Core/Platform/Windows/NullToUnsetValueConverter.cs
The loaded try-fix skill requires an attempt to report Blocked before editing whenever .github/.baseline-state.json has a non-empty NewFiles array. Each candidate must still run the mandated baseline command, capture the blocker honestly, create the required artifacts, and run the exact restore command. It must not bypass this boundary or alter the pre-existing unrelated working-tree changes under .github/ and eng/.
🔬 Code Review — Deep Analysis
Expert Code Review — PR #37755
Verdict: NEEDS_CHANGES
Confidence: High
Independent Assessment
The PR adds TabbedPage.BadgeText, TabbedPage.BadgeColor, and
TabbedPage.BadgeTextColor attached properties and maps them to Material
badges on Android, UITabBarItem badges on iOS/Mac Catalyst, and the existing
NavigationViewItemViewModel/InfoBadge path on Windows. The overall design is
additive and generally sound: it preserves native defaults, handles index reuse,
clears tracking state during reconnect, and includes focused managed and device
coverage.
Actionable Findings
- Android overflow cleanup targets a nonexistent menu ID.
TabbedPageManager.cs:391callsRemoveBadge(maxItems - 1)after
BottomNavigationViewUtils.SetupMenuhas removed that item and created the
overflow item asMoreTabId. The following mapping cleanup already removes
stale real-item badge IDs, so this call should be removed rather than aimed at
an unrelated slot. - Bottom badge refresh is not idempotent when colors are cleared.
TabbedPageManager.cs:472only recreates the native badge when the immediate
propertyNameidentifies the cleared color. Full and deferred refreshes pass
null, allowing a surviving drawable to retain stale custom colors. - Top badge refresh has the same stale-color path.
TabbedPageManager.cs:524likewise depends onpropertyName, although a
deferred refresh drops that information. - The overflow test cannot detect the cleanup defect.
TabbedPageTests.Android.cs:226starts with six children, so IDs 4 and 5
never exist and the More item is never badged. A five-to-six-child transition
is needed to prove the former fifth slot is cleared.
Raw file-and-line findings are recorded in ../inline-findings.json.
Blast Radius and Failure-Mode Probing
- Existing
TabbedPageinstances without badge values stay on removal/skip
paths; there is no startup or global-state impact. - Page insertion and index reuse are guarded by the page-to-index maps, which
are cleared inSetElement. - Empty collections and temporarily unavailable native views are deferred
safely, but that deferral exposes the stale-color defect because it discards
propertyName. - Apple and Windows implementations preserve native defaults and propagate
runtime updates through their existing platform infrastructure. - The Android More-item cleanup is ineffective during the transition into
overflow, and the current test starts too late to observe it.
Reviewer Recommendation
Apply one consolidated Android patch that removes the dead overflow cleanup,
makes both badge application methods reconstruct default colors from current
state rather than event provenance, and strengthens the overflow transition
test. This feedback can improve the submitted PR without changing its public API
or cross-platform design.
🛠️ Try-Fix — Analysis & Comparison
PR #37755 Alternative Fix Candidates
Candidate 1 — Adapter-Owned Construction-Time Badge Binding
Model: claude-opus-5
Result: Blocked
Candidate report: ../try-fix-1/content.md
Attempt artifacts: attempt-1/
Approach
Apply badge state where each native tab item/view is created and bound to its Page, making the badge a derived property of a materialized tab view. Runtime property changes would route to one ApplyBadge(tabView, page) operation: update text in place, and remove/recreate only when a previously customized color is cleared. Overflow would be handled by which native items are constructed.
Difference From the PR
The PR uses TabbedPageManager as an eventual-consistency reconciler with _bottomBadgePages and _topBadgePages, _badgesNeedUpdate, ViewPager.Post, layout retries, readiness checks, and full index reconciliation. Candidate 1 instead applies badge state during tab construction, when both the native view and its source Page are already known. That would eliminate readiness retries and make insertion/index reuse derive from binding rather than side dictionaries.
Implementation and Diff
No source files were changed.
(empty)Test Results
Neither permitted command was run:
dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter "FullyQualifiedName~TabbedPageBadgeTests"
pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Controls -Platform android -TestFilter "Category=TabbedPage"Running them without a safely established broken baseline would only retest the PR implementation and would not validate this candidate.
Blocker Analysis
The mandatory baseline command failed with DIRTY WORKING DIRECTORY because the repository already contains unrelated changes under .github/ and eng/. Those paths are pre-existing work and cannot be cleaned or altered by the attempt. .github/.baseline-state.json was not created, so the skill prohibited all source edits.
The PR also adds two non-test production files (TabbedPageBadgePage.cs and NullToUnsetValueConverter.cs). Even if the worktree were otherwise clean, a non-empty baseline NewFiles array independently requires a Blocked-before-editing result under the loaded skill.
Inline self-review recorded zero findings because there was no candidate diff. The exact restore command completed with the permitted no-state result: No baseline state found, Restored False.
Candidate 2 — Native Hierarchy Page-Identity Binding
Model: gpt-5.6-sol
Result: Blocked
Candidate report: ../try-fix-2/content.md
Attempt artifacts: attempt-2/
Approach
Observe native tab child attachment/detachment and bind each materialized native tab to its MAUI Page identity. Badge updates would resolve the native item through that page identity rather than maintaining index-to-page dictionaries. Native replacement or detachment would naturally discard stale badge ownership, while page property changes would update only the currently bound native item.
Difference From Earlier Approaches
This does not use the PR's deferred full reconciliation, readiness flag, posted retries, or index dictionaries. It also does not use Candidate 1's adapter/construction-time hook. Candidate 2 makes the native hierarchy lifecycle authoritative: attach establishes page identity, detach removes ownership, and runtime updates target the active identity binding. Index insertion/reuse therefore cannot transfer a badge from one page to another.
Implementation and Diff
No source files were changed.
(empty)Test Results
Neither permitted command was run:
dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter "FullyQualifiedName~TabbedPageBadgeTests"
pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Controls -Platform android -TestFilter "Category=TabbedPage"The mandatory baseline command again rejected the pre-existing dirty .github/ and eng/ paths before creating .github/.baseline-state.json. Editing or testing an alternative without a valid baseline would violate the skill boundary and would only exercise the PR implementation already present in HEAD.
Blocker Analysis
Candidate 2 independently reproduced the baseline environment blocker and did not clean, overwrite, or restore unrelated work. The PR's two new non-test production files would also produce the skill's non-empty-NewFiles blocker if the dirty-worktree check were removed.
Inline self-review completed with zero findings because there was no candidate diff. The exact restore command returned the permitted no-state result: No baseline state found, Restored False.
Aggregate Outcome
Two mechanism-level alternatives were bounded and recorded, but neither could be implemented or empirically compared. Both are Blocked, not failed fixes: the mandatory baseline could not safely start against the pre-existing dirty worktree, and the PR contains added production files that the loaded skill declares non-restorable. No source code or gate artifact was modified, and no unrequested tests were run.
🏁 Report — Final Recommendation
⚠️ Final Recommendation: REQUEST CHANGES
Winner: pr-plus-reviewer
The submitted PR has a strong cross-platform design and its trusted Gate passed,
but the expert review found Android refresh paths that can retain custom native
badge colors after the attached colors are cleared. It also found that the
overflow test starts after overflow already exists and therefore cannot verify
the transition that must clear the former fifth badge.
pr-plus-reviewer is the single winning candidate because it resolves those
findings without changing the PR's API or cross-platform architecture. It tracks
the custom-color state actually applied to each Android badge slot, so
full/deferred reconciliation restores native defaults based on state transitions
rather than a transient PropertyChanged name. It also preserves badge identity
for ordinary text-only updates and exercises the five-to-six-tab overflow
transition.
Candidate Comparison
| Rank | Candidate | Implementation | Regression evidence | Assessment |
|---|---|---|---|---|
| 1 | pr-plus-reviewer |
Consolidated Android state-aware refinement and discriminating overflow test | Managed badge tests: 9/9 passed. Android Category=TabbedPage: 62/62 passed. |
Winner. Resolves the expert findings while preserving native defaults, page/index isolation, and text-update badge identity. |
| 2 | pr |
Submitted cross-platform badge implementation | Trusted Gate passed without the fix and passed with it; submitted managed and Android regression surfaces passed. | Sound overall, but the expert review identified non-idempotent Android color resets on deferred/full refresh and insufficient overflow-transition coverage. |
| 3 | try-fix-1 |
Adapter-owned construction-time binding was designed but not implemented. | Not run; candidate was blocked before editing. | Mechanically distinct idea, but it has no diff or empirical evidence and cannot outrank passing implementations. |
| 4 | try-fix-2 |
Native-hierarchy page-identity binding was designed but not implemented. | Not run; candidate was blocked before editing. | Also distinct but unimplemented and unvalidated. |
No candidate failed a regression test. The two try-fix-* candidates were
blocked and therefore rank below both candidates with passing evidence.
Required PR Changes
Apply pr-plus-reviewer/reviewer.patch to the submitted PR. The candidate is
based on the exact supplied sandbox baseline, has no commit, and its complete
PR-base-relative diff is recorded in pr-plus-reviewer/candidate.patch.
📱 UI Tests — TabbedPage
Detected UI test categories: TabbedPage
✅ Deep UI tests — 77 passed, 0 failed across 1 category on platform-pool agent (replaces in-process counts above).
🧪 UI Test Execution Results (deep, platform pool)
| Category | Tests | Snapshot diffs |
|---|---|---|
TabbedPage |
77/77 ✓ | — |
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs) |
🧭 Next Steps — reviewer changes required
The reviewer-enhanced candidate identified changes that are not yet in the submitted PR.
Why: The reviewer-refined PR fixes deferred Android badge color resets and adds a discriminating overflow-transition test while preserving the submitted cross-platform design. Its managed badge tests passed 9/9 and its Android TabbedPage device tests passed 62/62; both try-fix alternatives were blocked without implementations.
Address the actionable findings in this review before merging.
|
Empirically validated reviewed head iOS - PASS
pr37755-ios.mp4Android - PASS
pr37755-android.mp4 |
TabbedPageTests.Windows.cs (added by #37755) calls AssertEventually(...) without 'using static Microsoft.Maui.DeviceTests.AssertHelpers;', breaking the net11.0 Windows build for every PR (CS0103). Every sibling partial of the class already has this using; the Windows partial was the only one missing it. This carries the same one-line fix as #37818 so this PR's own CI can compile the Windows leg and produce consumable packages. It self-heals once net11.0 (with #37818) is merged in — the identical line merges cleanly and drops from this PR's diff. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 2ca68fe1-bef6-46a6-a0fd-17b7654cef34
… to TabbedPageTests.Windows.cs (#37818) <!-- 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! ## Description PR #37755 added Windows TabbedPage badge tests that call `AssertEventually`, but `TabbedPageTests.Windows.cs` was missing the static import for `Microsoft.Maui.DeviceTests.AssertHelpers`. This causes CS0103 in both net11.0 Windows TFMs and blocks the Debug and Release Windows builds for every PR targeting `net11.0`. This adds the same `using static Microsoft.Maui.DeviceTests.AssertHelpers;` directive already present in every sibling `TabbedPageTests` partial. No test logic or runtime behavior changes. ## Verification Verified by code inspection that the sibling partials use the same static import and that `AssertHelpers.AssertEventually(Func<bool>, ...)` exists. Windows compile verification is deferred to CI because the local host is macOS and cannot build the `net11.0-windows` TFMs. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Adds BadgeText/BadgeColor/BadgeTextColor (dotnet/maui#37755) to TizenTabbedPageHandler as documented no-ops, matching upstream's own support matrix for Tizen, and regenerates the parity artifacts. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Description of Change
Adds badge support to regular
TabbedPagechildren through the same attached-property model and semantics used by Shell:TabbedPage.BadgeTextTabbedPage.BadgeColorTabbedPage.BadgeTextColorThe platform implementations support initial values and runtime updates:
UITabBarItem.BadgeValue,BadgeColor, andSetBadgeTextAttributes.NavigationViewItemViewModel/InfoBadgeinfrastructure while preserving native theme defaults when colors are unset.Includes managed API tests, Android and Apple native tests, and an interactive Controls.Sample page.
Apple badge color limitation
UIKit's modern tab-bar renderer, introduced in iOS and Mac Catalyst 18, may retain custom
UITabBarItembadge colors while visually rendering the system red/white colors. The implementation keeps using Apple's supported, non-deprecated per-item APIs so colors continue to work on older/legacy layouts and if UIKit restores the behavior.UITabBarItem.StandardAppearanceis intentionally not used as a fallback: Apple documents it as overriding the appearance of the whole tab bar while that item is selected, so it cannot provide independent per-tab badge colors.Validation
TabbedPagetestsTabbedPagedevice tests: 15 passed, 1 skippedTabbedPagedevice tests: 13 passed, 3 skippedIssues Fixed
N/A