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

Support for CoordinatorLayout added #96

Closed
wants to merge 10 commits into from

Conversation

MFlisar
Copy link
Contributor

@MFlisar MFlisar commented Jul 15, 2017

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...

MFlisar and others added 10 commits February 10, 2017 10:37
…ollBar class. This way, the MaterialScrollBar can keep it's package internal visibility and still people can use a public custom interface for both scroll bars

* added a setEnabled function to disable the need to force a RecyclerView to be attached to the scroll bar
* don't consume the touch if setDraggableFromAnywhere is false + the wrong region is touched in ondown touch event
@turing-tech
Copy link
Owner

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
Copy link
Owner

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
Copy link
Contributor Author

MFlisar commented Jul 15, 2017

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
Copy link
Contributor Author

MFlisar commented Jul 17, 2017

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
Copy link
Owner

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
Copy link
Contributor Author

MFlisar commented Jul 24, 2017

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
Copy link
Owner

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

@turing-tech turing-tech closed this Aug 7, 2017
@turing-tech
Copy link
Owner

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
Copy link
Owner

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.

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

Successfully merging this pull request may close these issues.

None yet

2 participants