title: How to tell when BottomSheetDialogFragment expanded to fill the screen?
body: <p>I'm trying to follow the Material Design <a href="https://www.material.io/design/components/sheets-bottom.html#behavior" rel="nofollow noreferrer">specification</a> to add a close affordance toolbar to a modal bottom sheet using the Android Design Support library.</p>
  
  <blockquote>
    <p>When full-screen, bottom sheets can be internally scrolled to reveal additional content. <strong>A toolbar should be used to provide a collapse or close affordance to exit this view</strong>.</p>
  </blockquote>
  
  <p>I went with <code>BottomSheetBehavior.BottomSheetCallback</code> to toggle the visibility of the toolbar based on the expanded/collapsed state of the <code>BottomSheetBehavior</code>. The problem is the toolbar appears when I try to drag up, even if the <code>BottomSheetDialogFragment</code> content can't fill the entire screen. How can I tell when the bottom sheet is fullscreen while the bottom sheet is expanding?</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class BottomSheetToolbarToggleCallback : BottomSheetBehavior.BottomSheetCallback
  {
      public BottomSheetToolbarToggleCallback(BottomSheetDialogFragment bottomSheetDialogFragment)
      {
          this.bottomSheetDialogFragment = bottomSheetDialogFragment ?? throw new System.ArgumentNullException(nameof(bottomSheetDialogFragment));
      }
  
      public override void OnSlide(View bottomSheet, float slideOffset)
      {
      }
  
      public override void OnStateChanged(View bottomSheet, int newState)
      {
          switch (newState)
          {
              case BottomSheetBehavior.StateCollapsed:
                  ShowToolbar(bottomSheet, ViewStates.Gone);
                  break;
              case BottomSheetBehavior.StateExpanded:
                  ShowToolbar(bottomSheet, ViewStates.Visible);
                  break;
              case BottomSheetBehavior.StateHidden:
                  bottomSheetDialogFragment.Dismiss();
                  break;
          }
      }
  
      private void ShowToolbar(View bottomSheet, ViewStates viewState)
      {
          var toolbar = bottomSheet.FindViewById&lt;Toolbar&gt;(Resource.Id.toolbar);
          if (toolbar != null)
          {
              toolbar.Visibility = viewState;
          }
      }
  
      private readonly BottomSheetDialogFragment bottomSheetDialogFragment;
  }
  </code></pre>
  
  <pre class="lang-cs prettyprint-override"><code>public abstract class BaseBottomSheetDialogFragment&lt;TViewModel&gt; : MvxBottomSheetDialogFragment&lt;TViewModel&gt; where TViewModel : BaseViewModel
  {
      protected BaseBottomSheetDialogFragment()
      {
      }
  
      protected BaseBottomSheetDialogFragment(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
      {
      }
  
      public override void SetupDialog(Dialog dialog, int style)
      {
          base.SetupDialog(dialog, style);
  
          this.EnsureBindingContextIsSet(); // This is required to use this.BindingInflate()
          var view = this.BindingInflate(LayoutResourceId, null);
          dialog.SetContentView(view);
  
          // Add support to handle material design specification to dynamically show a toolbar with an 'X' button.
          var layoutParams = (CoordinatorLayout.LayoutParams)((View)view.Parent).LayoutParameters;
          var behavior = layoutParams.Behavior;
          if (behavior != null &amp;&amp; behavior is BottomSheetBehavior)
          {
              var toolbar = view.FindViewById&lt;Toolbar&gt;(Droid.Resource.Id.toolbar);
              if (toolbar != null)
              {
                  toolbar.SetNavigationIcon(Droid.Resource.Drawable.clear);
                  ((BottomSheetBehavior)behavior).SetBottomSheetCallback(new BottomSheetToolbarToggleCallback(this));
                  if (CloseCommand != null)
                  {
                      toolbar.SetNavigationOnClickListener(new MvxAsyncCommandOnClickListener(CloseCommand));
                  }
              }
          }
      }
  
      /// &lt;summary&gt;
      /// The Android layout resource id of the layout to show in the modal bottom sheet.
      /// &lt;/summary&gt;
      protected abstract int LayoutResourceId { get; }
  
      /// &lt;summary&gt;
      /// Optional &lt;see cref="MvxAsyncCommand"/&gt; to call when the optional toolbar navigation button is clicked.
      /// &lt;/summary&gt;
      protected abstract IMvxAsyncCommand CloseCommand { get; }
  }
  </code></pre>