question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add Shell Badge support

See original GitHub issue

Description

Add badge support to Shell. Description copied from this original issue for Xamarin.Forms.

Public API Changes

Badges should be supported on all shell navigation patterns, which are

  • Flyout menu items
  • Bottom tabs
  • Top tabs

I propose the following properties for first iteration of badge support:

Primary properties

BaseShellItem (bindable properties)

  • BadgeText: string to set the number (or something else) of notification-like items
  • BadgeMoreText: string to set the number (or something else) of the aggregated more tab
  • BadgeTextColor: Foreground color of badge text
  • BadgeUnselectedTextColor: Foreground color of badge text if underlying navigation item is in unselected state
  • BadgeEffectiveTextColor (readonly): If BadgeUnselectedTextColor is unset, BadgeTextColor will be returned. Otherwise it will return BadgeTextColor if the underlying navigation item is in selected state or BadgeUnselectedTextColor if in unselected state.
  • BadgeColor: background color of badge
  • BadgeUnselectedColor: background color of badge if navigation item is in unselected state
  • BadgeEffectiveColor (readonly): If BadgeUnselectedColor is unset, BadgeColor will be returned. Otherwise it will return BadgeColor if the underlying navigation item is in selected state or BadgeUnselectedColor if in unselected state.

Future implementations / considerations

  • Add font image support (might also work for “little dot mode”)
  • CSS Styling
  • Inheritance of styling related properties
  • Additional More properties (TextColor, UnselectedTextColor, Color, UnselectedColor, …)

Bottom tabs use the concept of the More tab if there are more than 5 items. All items with index >= 5 will be “hidden” by this more tab and handled by a platform specific context menu.

One use case would be the transformation of the underlying items hidden by this more tab. For example Item 5 (Messages) has “1” new item and Item 6 (Notifications) has “2” new items, so you could show “3” in the more tab, but the user would not how how this is split between the aggregated items.

We could think of modifying the text (e.g. for the example above “Messages (1)” and “Notifications (6)”). I’m proposing this because adding a badge to the underlying platform specific context menu could be too much work / impossible for a specific platform. Modifying the title value should definitely work though and we would see at least something.

Internal implementation

Android

Material components will support badges out of the box, which when I understood it correctly can be used when AndroidX is supported by Xamarin. In the meantime we have to supply a custom implementation like this for badges.

Flyout

Flyout menu is created by the ShellFlyoutTemplatedContentRenderer in combination with ShellFlyoutRecyclerAdapter. The data template is based on forms controls, so we just might use a Frame here for the default template. For custom templates the user has to provide the necessary controls and bind color, text, etc…

Bottom tabs

ShellItemRenderer uses BottomNavigationView, which can be used to retrieve the underlying BottomNavigationItemView items and inject the badge view.

The more tab uses a BottomSheetDialog.

Top tabs

ShellSectionRenderer uses TabLayout, which can be used to retrieve the underlaying TabView items and inject the badge view.

iOS

Flyout

Flyout menu is created by the ShellTableViewController in combination with ShellTableViewSource. The data template is based on forms controls, so we just might use a Frame here for the default template. For custom templates the user has to provide the necessary controls and bind color, text, etc…

Bottom tabs

ShellItemRenderer uses UITabBarController which can use the UITabBarItem to specify native Badge properties.

The more tab uses the default implementation of the MoreNavigationController of UITabBarController.

Top tabs

ShellSectionRootRenderer uses a UICollectionView, so you would have to modify ShellSectionHeaderCell and add a custom badge view (something like this).

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:11
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
DavidChoi2022commented, Oct 10, 2022

Badge in tab is useful, and it is also an indispensable part of the UI system. come on!

4reactions
victordscottcommented, Apr 6, 2023

This was holding me up from converting a Xamarin Forms application to Maui. I converted code from the Xam.Shell.Badge plugin and pulled it into my application to solve this for iOS and Android. Here is a sample application you can start with:

https://github.com/victordscott/MauiShellBadgeTest

Read more comments on GitHub >

github_iconTop Results From Across the Web

Emergency Preparedness Employee Badge Card - 2019
Check and update your contact details NOW! • Consider the best method for you to be reached in an emergency – personal phone,...
Read more >
Xamarin forms Shell ToolBar Badge - Microsoft Q&A
How to add Badge to toolbar with shell, I tried many option including XCT badgeview also, but no success. Xamarin.
Read more >
[NEW] - How to make a BADGE COMMAND for your discord bot!
This is how you can make a badge command for your discord bot! Join my discord (FOR BADGES ): https://discord.gg/E6AJ7eNrsd Want to become ......
Read more >
Badges - Documentation
A badge is a large text label that appears in the top right of a terminal session to provide dynamic status, such as...
Read more >
Don't Lose Your Head With iTerm2
Shell integration allows to create variables and use them, we would like to create a variable that will hold the badge text just...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found