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

How to display scroll bar on the left for right-to-left layouts? #70

Closed Mina-H-Samy closed 7 years ago

Mina-H-Samy commented 7 years ago

Is there a way to display the scrollbar on the left hand side of the screen for right-to-left languages? Doesn't look like this is exposed through a public method so is it easy to override this in some other way?

turing-tech commented 7 years ago

I've been a bad developer and avoided coding it :P I can do it tomorrow though.

Mina-H-Samy commented 7 years ago

so turns out I'm actually not going to use it in my project after all so no rush at all. But yeah would be useful nonetheless!

Mina-H-Samy commented 7 years ago

mm you know what I take that back, I will use it :P

But you don't have to do this yourself, if you give me a few pointers I can do it myself and create a PR :)

turing-tech commented 7 years ago

So I would actually do a refactor and remove the whole system of adding the scroll bar programatically and just have people add it in XML. I've been planning to do this and frankly it would just make things a lot simpler. If that's too complicated to do let me know and I can go ahead and do that bit.

After that you would need to use this solution to detect RTL layouts and then reverse all of the animation values where applicable. If you need help doing this too just let me know.

Mina-H-Samy commented 7 years ago

ok so is the refactor related to this? Since that would be a breaking change I imagine you would want to deprecate the programmatic way somehow before removing it completely?

Would it make sense to just do the RTL support now without the refactor?

Oh and I don't know if that solution is what I'm looking for... So sometimes the device's language is using a LTR language but it is only the text in my recyclerview that is RTL, and so I'd probably need a 'setRTL(boolean)' on the scrollbar

turing-tech commented 7 years ago

I'm doing it right now actually. I'll have it in a few minutes.

Mina-H-Samy commented 7 years ago

wow you're fast! And the new version is already released too! Thank you very much! A small donation coming your way - dinner's on me :)

Mina-H-Samy commented 7 years ago

so I just tested 11.2.0 and the right to left works beautifully! Except now I think the left to right is broken. If I setRightToLeft(false) or if I do not call that method at all, I still get the scroll bar on the left side but with the LTR drawable:

screenshot_1481016341

turing-tech commented 7 years ago

Holy crap, thanks! As far as the alignment goes, have you set alignParentRight to true? The bar won't align itself, so if you want it to operate in a LTR mode you need to set the bar up in the right side of the screen.

Mina-H-Samy commented 7 years ago

You mean alignParentRight on the DragScrollBar itself, yes?

I can't seem to be able get it to work correctly still. It looks like for RTL the indicator appears to the left of the screen (so it is off screen).

In the XML I have none of the layout_ params except height and width. And in the code I call setRightToLeft(isRTL)

and also:

capture

With that setup, the LTR works fine, but the RTL, the indicator shows to the LEFT of the scrollbar (and the scrollbar itself is on the left, so the indicator is shown off-screen). I am using a the CustomIndicator() btw.

Here is how you can test if this works on your side: Have your phone locale in English, and display all English text in the RecyclerView. Now, are you able to get the scrollbar to show on the left and the right based on your code and not on your locale?

turing-tech commented 7 years ago

Just to clarify, what's the system direction during this time? Is the isRTL function asking about an in app setting?

Mina-H-Samy commented 7 years ago

yes just an app setting, I have itsuch that users can specify which language they want regardless of system locale. As in: I don't care what's the system direction, if my recyclerview is using a LTR language then I want scrollbar on the right, and on the left for RTL language.

turing-tech commented 7 years ago

So the ALIGN_PARENT_END rule is going to align based on the system detected locale. The library does not alter the layout of the bar at all. If the bar is appearing on the wrong side of the screen then that's an issue in the layout rules that the developer is using, not the library.

You should probably assign the ALIGN_PARENT_RIGHT or ALIGN_PARENT_LEFT rule and not have an END or START rule at all.

Mina-H-Samy commented 7 years ago

ah I found the culprit... It was that I had the DragScrollBar in a separate xml file and I was inflating it manually and adding it to the RelativeLayout (the recyclerview's parent). For some reason that caused the scrollbar to be erratic.

Anyway, works great now. I really appreciate you coding this up that fast, thanks very much!