Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Shell Badge support #8305

Open
angelru opened this issue Jun 24, 2022 · 18 comments
Open

Add Shell Badge support #8305

angelru opened this issue Jun 24, 2022 · 18 comments
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout delighter proposal/open t/enhancement ☀️ New feature or request
Milestone

Comments

@angelru
Copy link

angelru commented Jun 24, 2022

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).

@Eilon Eilon added the area-controls-shell Shell Navigation, Routes, Tabs, Flyout label Jun 24, 2022
@jfversluis
Copy link
Member

Copied the description from the original issue for Xamarin.Forms into here. I think some work even has been done at some point, so we might be able to salvage some code from there.

@jfversluis jfversluis changed the title Shell badges Add Shell Badge support Jun 27, 2022
@Reed-Anderson
Copy link

What's the process for approving proposals like this? Is it likely for this to be approved and implemented within the next 6 months or so?

@angelru
Copy link
Author

angelru commented Oct 3, 2022

What's the process for approving proposals like this? Is it likely for this to be approved and implemented within the next 6 months or so?

I don't know how long it will take to approve it.

@DavidChoi2022
Copy link

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

@lucianparvu
Copy link

It is there a workaround ? From where can i start to make custom tabs with some badges and use shell in the same time ?

@angelru
Copy link
Author

angelru commented Nov 4, 2022

@lucianparvu

You can create a shell app that contains a page and within the page a view with https://github.com/roubachof/Sharpnado.Tabs

@swetaVanjara
Copy link

any example around this. I've added badge in iOS. how can i add in android ??

@mattleibow mattleibow added this to the Backlog milestone Apr 3, 2023
@ghost
Copy link

ghost commented Apr 3, 2023

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@mattleibow mattleibow added the t/enhancement ☀️ New feature or request label Apr 3, 2023
@victordscott
Copy link

victordscott commented 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

@dongfo
Copy link

dongfo commented Apr 24, 2023

any one work on it ?

@Kol-yan
Copy link

Kol-yan commented Apr 27, 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

Thank you so much for sharing this!

@bidianqing
Copy link

any one work on it ? @jfversluis

@Abhayprince
Copy link

Got it working with custom platform specific shell handlers for Android and iOS
https://github.com/Abhayprince/TabbarBadgeShellMAUI

@Cybrosys
Copy link

Cybrosys commented Dec 18, 2023

Any update on this? I've looked at @Abhayprince 's example, but it hardcodes the tab index. I'm trying to achieve a more dynamic solution where in the renderer I could find pages that inherit from my base class or use a message from the page that includes some ID that I can identify in the renderer.

For now I'm getting a page's index with this in the ctor of the ContentPage:

var currentSection = Shell.Current.CurrentItem;
var currentContent = currentSection.CurrentItem.CurrentItem;
Index = currentSection.Items.IndexOf(currentContent);

My base ContentPage has a bindable property BadgeCountProperty which uses the WeakReferenceMessenger to send a message that my appearance tracker is listening for.

@smhasan
Copy link

smhasan commented Feb 21, 2024

@Cybrosys Would you like to share example code

@tonyedwardspz
Copy link

@Abhayprince That's the perfect starting point for me. Thanks for putting it together.

I'm struggling to get the badge color to chage to anything other than red, which is the iOS platform default. Did you have any luck using any other colors when creating that tutorial?

@angelru
Copy link
Author

angelru commented Mar 23, 2024

is there news?

@tonyedwardspz
Copy link

tonyedwardspz commented Jun 18, 2024

For anyone ending up here looking for a solution to changing the badge color on iOS, check out this answer to my
SO question..

For Android, refer to the github project shared by Abhay further up the thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout delighter proposal/open t/enhancement ☀️ New feature or request
Projects
None yet
Development

No branches or pull requests