I have been following the jiant initial github test project project on this issue, and I am happy to share with you a solution for some of its problems, since I also needed this behavior in my application.
this is the solution to his problem: ❌ the toolbar sometimes crashes too soon
to prevent this, you need to create your own custom AppBarLayout.Behavior , since this is when you scroll up while still dragging that AppBarLayout.Behavior gets the scroll motion. We need to determine if it is in STATE_DRAGGING and just go back to prematurely hide / collapse the toolbar.
public class CustomAppBarLayoutBehavior extends AppBarLayout.Behavior { private CoordinatorLayoutBottomSheetBehavior behavior; public CustomAppBarLayoutBehavior() { } public CustomAppBarLayoutBehavior(Context context, AttributeSet attrs) { super(context, attrs); } @Override public boolean onStartNestedScroll(CoordinatorLayout parent, AppBarLayout child, View directTargetChild, View target, int nestedScrollAxes) { behavior = CoordinatorLayoutBottomSheetBehavior.from(parent); return super.onStartNestedScroll(parent, child, directTargetChild, target, nestedScrollAxes); } @Override public void onNestedPreScroll(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, int dx, int dy, int[] consumed) { if(behavior.getState() == CoordinatorLayoutBottomSheetBehavior.STATE_DRAGGING){ return; }else { super.onNestedPreScroll(coordinatorLayout, child, target, dx, dy, consumed); } } @Override public void setDragCallback(@Nullable DragCallback callback) { super.setDragCallback(callback); } }
this may be a good start to how we solve other problems:
❌ toolbar cannot be demolished by dragging and dropping
❌ location of the main coordinator consumes several scrolls
I'm actually not a good user interface / animation, but hard work pays off, sometimes understanding the code, finding the right callback / override function.
set this as behavior for appbarlayout
<android.support.design.widget.AppBarLayout android:id="@+id/bottom_sheet_appbar" style="@style/BottomSheetAppBarStyle" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_behavior="your.package.CustomAppBarLayoutBehavior">