zhanghai/MaterialProgressBar

HorizontalProgressBar Right-to-Left doesn't work

Closed this issue · 3 comments

RTL doesn't work, add:

<me.zhanghai.android.materialprogressbar.MaterialProgressBar
            android:id="@+id/indeterminate_horizontal_progress_library_rtl"
            android:layoutDirection="rtl"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:indeterminate="true"
            app:mpb_progressStyle="horizontal"
            style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal" />

to main_activity.xml and the progress bar will act the same as the LTR progress bar:

rtl

I'm actually working on a solution, but:

private boolean needMirroring() {
        return mAutoMirrored
                && DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL;
    }

needs a rewrite.
It can never be right because this library is targeting api 14 as the min sdk version, but LayoutDirection and rtl support got in on api 17.

@DreaminginCodeZH what do you say about another enum attribute (direction: ltr, rtl) or boolean attribute (rtl: true/false) which will handle the direction of the horizontal progress bars?

I'm not going to backport RTL support because at API level < 17 the whole platform itself won't support RTL.

I've investigated a bit why RTL doesn't work on API level >= 17, and the reason is that the ProgressBar itself does the mirroring if RTL is enabled, so if we do another mirroring in the ProgressDrawableBase the result is restored to LTR. I've removed the mirroring code and now it works perfectly (with force RTl enabled in my dev options).

rtl

I'm closing this issue and that PR. If you have any other comments please leave them here.

I think that if the library is targeting min sdk 14 it'll be good if backport rtl support will be available.
screen shot 2016-07-14 at 10 12 03 am
A lot of rtl (arabic, hebrew etc) projects are targeting low api so they won't lose these 8.7% devices, I personally work on a project that has api 16 as the minimum and needs that rtl backport.
I hope you'll get my point, but, it's your decision after all.

Maybe you should backport RTL on ProgressBar instead. For example backporting rtlpb_mirrorForRtl and overriding onDraw(). That would be another nice little project.