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

bottomsheet behind tabbar #115

Closed
takennnusernames opened this issue May 23, 2024 · 5 comments
Closed

bottomsheet behind tabbar #115

takennnusernames opened this issue May 23, 2024 · 5 comments

Comments

@takennnusernames
Copy link

is there a way to put the bottom sheet behind the shell.tabbar? i am try to make it as isCancelable=false but still show the tabbar

@vhugogarcia
Copy link

Could you please share a sample repository on GitHub showing the issue?

@peruchali
Copy link

peruchali commented Aug 5, 2024

Could you please share a sample repository on GitHub showing the issue?

@vhugogarcia
You can add Shell.TabBarIsVisible="True" to AppShell.xaml's Shell element in the sample project to repro (the TabBar shows up at the bottom). The bottom sheet always shows in front of the tab bar (obscuring it) rather than vertically above it (tested on Android). It feels like there should be an option to show the bottom sheet either vertically above the tab bar (desired behavior of this issue) or covering it entirely (current behavior).

@peruchali
Copy link

Here's what worked for me:

  class TabBarPositionCallback : BottomSheetBehavior.BottomSheetCallback
  {
      private readonly BottomSheet m_bottomSheet;

      public TabBarPositionCallback(BottomSheet bottomSheet)
      {
          m_bottomSheet = bottomSheet;
      }

      public override void OnSlide(Android.Views.View bottomSheet, float newState) =>
          SetMarginFromTabBar(bottomSheet);

      public override void OnStateChanged(Android.Views.View bottomSheet, int p1) =>
          SetMarginFromTabBar(bottomSheet);

      private void SetMarginFromTabBar(Android.Views.View bottomSheet)
      {
          if (bottomSheet.Parent is ViewGroup viewGroup)
          {
              // Show above navigation bar and tab bars rather than in front on them.
              Android.Views.Window window = ((AppCompatActivity)m_bottomSheet.Handler.MauiContext.Context).Window;
              Android.Views.View rootView = window.DecorView;

              WindowInsetsCompat windowInsets = ViewCompat.GetRootWindowInsets(rootView);
              AndroidX.Core.Graphics.Insets navigationBarsInset = windowInsets.GetInsetsIgnoringVisibility(WindowInsetsCompat.Type.NavigationBars());
              int bottomMargin = navigationBarsInset.Bottom;

              if (rootView is ViewGroup rootViewGroup &&
                  rootViewGroup.GetFirstChildOfType<BottomNavigationView>() is BottomNavigationView bottomNavigationView)
              {
                  bottomMargin += bottomNavigationView.Height;
              }

              ViewGroup.MarginLayoutParams layoutParameters = viewGroup.LayoutParameters as ViewGroup.MarginLayoutParams;
              layoutParameters.BottomMargin = bottomMargin;
          }
      }
  }

and add this callback with:

void OpenCustomizeBehavior()
{
    var page = new SimplePage();
    page.HasBackdrop = false;

    var callback = new TabBarPositionCallback(page);

    page.Showing += (s, e) =>
    {
        page.Controller.Behavior.AddBottomSheetCallback(callback);
        page.Controller.Behavior.DisableShapeAnimations();
    };
    page.ShowAsync(Window);
}

If HasBackdrop is false, this will show the bottomsheet above the tab/navigation bars.

@takennnusernames
Copy link
Author

hello, thanks for sharing @peruchali. i had already created a way around this issue. since the tabbar is always above the bottomsheet, when it is dismissed, it cannot be shown again because the tabbar is blocking the bottomsheet handler, so i created a button that would only show once the bottomsheet is dismissed, this button then activates the bottomsheet again once it is tapped. it would be very nice to have a future function that would place the bottomsheet handler above the tabbar.

@peruchali
Copy link

@takennnusernames You can check out #133

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

No branches or pull requests

3 participants