dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.01k stars 1.72k forks source link

[iOS] Allow UpdateTabBarHidden method in ShellItemRenderer to be overridden #19745

Open sebfrie opened 8 months ago

sebfrie commented 8 months ago

Description

I implemented a custom action button in the Shell TabBar with a CustomShellItemRenderer derived from ShellItemRenderer (following @VladislavAntonyuk's great blog post) but an added control (i.e., action button) does not react to setting Shell.TabBarIsVisible on a page.

Making the UpdateTabBarHidden method in the iOS implementation of ShellItemRenderer a protected virtual method would allow it to be overridden by derived classes which could handle added custom controls.

Public API Changes

Make UpdateTabBarHidden in the iOS implementation of ShellItemRenderer a protected virtual method instead of (implicitly) private. This would align with the Android implementation (see: ShellItemRenderer.cs)

https://github.com/dotnet/maui/blob/c3221bf08d291c9f69070aa11d6d60f61a569aae/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellItemRenderer.cs#L434 ->

protected virtual void UpdateTabBarHidden()

Intended Use-Case

This would allow for implementing a method that reacts to setting Shell.TabBarIsVisible and updates the visibility of added custom controls.

The Android implementation of ShellItemRenderer already has a protected virtual UpdateTabBarVisibility method that can be overridden in a CustomShellItemRenderer to keep the visibility of the custom action button in sync:

internal class CustomShellItemRenderer : ShellItemRenderer
{
  private Android.Widget.Button? centerView;
  ...
  // Create custom action button, i.e., centerView
  ...
  protected override void UpdateTabBarVisibility()
  {
      base.UpdateTabBarVisibility();

      if (DisplayedPage is null || centerView is null)
          return;

      centerView.Visibility = ShellItemController.ShowTabs ? ViewStates.Visible : ViewStates.Gone;
  }
}

The API change would allow something similar for iOS:

internal class CustomShellItemRenderer : ShellItemRenderer
{
  private UIButton? centerView;
  ...
  // Create custom action button, i.e., centerView
  ...
  protected override void UpdateTabBarHidden()
  {
      base.UpdateTabBarHidden();

      if (ShellItemController == null || centerView == null)
          return;

      centerView.Hidden = !ShellItemController.ShowTabs;
  }
}
ghost commented 8 months ago

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.