turing-tech / MaterialScrollBar

An Android library that brings the Material Design 5.1 sidebar to pre-5.1 devices.
Apache License 2.0
778 stars 126 forks source link

Support for CoordinatorLayout added #96

Closed MFlisar closed 7 years ago

MFlisar commented 7 years ago

Sadly the MaterialScrollBar sets up the LayoutParams of it's sub views before the it's layed out, this means, I can't check if the MaterialScrollBar is placed in a CoordinatorLayout. Therefore I had to add a xml attribute msb_placedInCoordinator. Based on this, the MaterialScrollBar can create RelativeLayout params or CoordinatorLayout params...

turing-tech commented 7 years ago

I'll take a look. This may be included in 12.5.0 so I'll hold off on releasing the version on github until I decide on that.

turing-tech commented 7 years ago

Can you give me an example layout file to test out how this works? I'm having a hard time understanding when you'd need a scroll bar as a direct child of a coordinator.

MFlisar commented 7 years ago

I can give you an example tomorrow....

But you need it as direct child if you want to attach it to some custom behaviour. Like pushing the recycler view and the scroll bar down when a top view expands or pushing them up if a bottom view appears. And you can't put the recycler view inside a relative layout with the scroll bar because then the coordinator can't react with the default scrolling view behaviour to scrolls in the recycler view. And additionally for full coordinator layout support we probably most of the time need some custom behaviour for the scroll bar... because now scrolling with the scroll bar does not have the scrolling effects that scrolling with the fast scroller have (showing and hiding views for example)

MFlisar commented 7 years ago

Do you really need an example? I've not yet written any custom behaviour. But in my case I have a search bar on top and a T9 keyboard on bottom. both views show up on scroll up and hide on scroll down, so the recyclerviews bounds change accordingly. The same should happen with the scrollbar....

turing-tech commented 7 years ago

I haven't really used coordinator layouts that much so it may just be that I don't know what I'm doing, but I can't get the bar to right-align without making it the child of a relative/constraint layout.

MFlisar commented 7 years ago

Here's the usage example with the scroll bar on the right:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/clMain"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/ablSidebar"
            android:background="@null"
            app:elevation="0dp"
            app:contentInsetLeft="0dp"
            app:contentInsetStart="0dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:background="@null"
                app:elevation="0dp"
                app:contentInsetLeft="0dp"
                app:contentInsetStart="0dp"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_scrollFlags="scroll|enterAlways">

            </android.support.v7.widget.Toolbar>

            <!-- BUG: http://stackoverflow.com/questions/30541409/coordinatorlayoutappbarlayout-does-not-draw-toolbar-properly -->
            <View
                android:layout_width="fill_parent"
                android:layout_height="1dp"/>

        </android.support.design.widget.AppBarLayout>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rvSidebar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

        <com.turingtechnologies.materialscrollbar.TouchScrollBar
            android:id="@+id/touchScrollBar"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="end|right"
            app:msb_recyclerView="@id/rvSidebar"
            app:msb_lightOnTouch="false"
            app:msb_placedInCoordinator="true" />

    </android.support.design.widget.CoordinatorLayout>

</RelativeLayout>

Those two lines are important to place the scroll bar inside a CoordinatorLayout and right align it:

android:layout_gravity="end|right"
app:msb_placedInCoordinator="true"
turing-tech commented 7 years ago

I'm going to edit this a bit and integrate it. Thanks for the help!

turing-tech commented 7 years ago

After looking at everything it looks like we made need to do a larger refactor in order to make things work elegantly. When I get some time (hopefully this month) I'll get to work on that. The problem is app:msb_placedInCoordinator shouldn't be necessary but everything gets set up before its laid out so the parent can't be accessed. We should move to a builder-view system but that is going to take a day or so of coding for me to do well.

turing-tech commented 7 years ago

Wait, actually, I take most of that back. Why do we even need to know about the parent in the first place? All of the subviews are being added to the bar itself which is a relative layout. It should be parent agnostic.