locked
Snackbar not pushing FAB up RRS feed

  • Question

  • User14506 posted

    My RecyclerView hides my FAB on scroll with the following behavior.

        [Register("HideMyFab.ScrollAwareFABBehavior")]
        public class ScrollAwareFABBehavior : CoordinatorLayout.Behavior
        {
            public ScrollAwareFABBehavior(Context context, IAttributeSet attrs) : base(context, attrs)
            {
            }
    
            public override bool OnStartNestedScroll(CoordinatorLayout coordinatorLayout, Java.Lang.Object child, View directTargetChild, View target, int nestedScrollAxes)
            {
                return nestedScrollAxes == ViewCompat.ScrollAxisVertical ||
                         base.OnStartNestedScroll(coordinatorLayout, child, directTargetChild, target, nestedScrollAxes);
            }
    
            public override void OnNestedScroll(CoordinatorLayout coordinatorLayout, Java.Lang.Object child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed)
            {
                base.OnNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
    
                var floatingActionButtonChild = child.JavaCast<FloatingActionButton>();
    
                if (dyConsumed > 0 && floatingActionButtonChild.Visibility == ViewStates.Visible)
                    floatingActionButtonChild.Hide();
                else if (dyConsumed < 0 && floatingActionButtonChild.Visibility != ViewStates.Visible)
                    floatingActionButtonChild.Show();
    
            }
        }
    

    But this behavior prevents the FAB from being pushed up when a snackbar message is present. Any ideas on how to implement both features?

    Thursday, August 11, 2016 6:41 AM

All replies

  • User14506 posted

    https://github.com/akamud/FloatingActionButton-Xamarin.Android/blob/bdabb453e40eff4235c497ea36f0a693d6e2326a/FAB.Sample/FloatingActionButtonBehavior.cs

    This resolved my issue.

    Friday, August 12, 2016 2:58 AM
  • User270307 posted

    Alright so you dont have to do all that.. All you have to do, in you XML containing the Floating Action button change the layout type ( "FrameLayout" as such) to

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/frameLayoutMain" 
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    

    and make sure you create an object of that in your activity as

    CoordinatorLayout LayoutMain;

    and add it to your SnackBar

    Snackbar
                                .Make(LayoutMain, "Timer Deleted", Snackbar.LengthLong)
                                .SetAction("Undo", (view) => { db.insertIntoTablePerson(person); LoadData(); })
                                     .Show();
    
    Sunday, November 13, 2016 11:21 PM