Unverified Commit 3d40cb71 authored by Hussein El Feky's avatar Hussein El Feky Committed by GitHub

Let drawables be set correctly in RTL languages

parent 5ceacaf2
import android.content.Context import android.content.Context
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.view.View
import android.widget.TextView import android.widget.TextView
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.DrawableCompat import androidx.core.graphics.drawable.DrawableCompat
...@@ -60,7 +61,7 @@ object DrawableHelper { ...@@ -60,7 +61,7 @@ object DrawableHelper {
/** /**
* Tints a Drawable. * Tints a Drawable.
* *
* REMARK: you MUST always wrap the Drawable before tint it. * REMARK: you MUST always wrap the Drawable before tinting it.
* *
* @param drawable The Drawable to tint. * @param drawable The Drawable to tint.
* @param context The context. * @param context The context.
...@@ -74,7 +75,7 @@ object DrawableHelper { ...@@ -74,7 +75,7 @@ object DrawableHelper {
/** /**
* Compounds an array of Drawable (to appear to the left of the text) into an array of TextView. * Compounds an array of Drawable (to appear to the left of the text) into an array of TextView.
* *
* REMARK: the number of elements in both array of Drawable and EditText MUST be equal. * REMARK: the number of elements in both array of Drawable and TextView MUST be equal.
* *
* @param textView The array of TextView. * @param textView The array of TextView.
* @param drawables The array of Drawable. * @param drawables The array of Drawable.
...@@ -85,7 +86,11 @@ object DrawableHelper { ...@@ -85,7 +86,11 @@ object DrawableHelper {
return return
} else { } else {
for (i in textView.indices) { for (i in textView.indices) {
if (textView[i].resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_LTR) {
textView[i].setCompoundDrawablesWithIntrinsicBounds(drawables[i], null, null, null) textView[i].setCompoundDrawablesWithIntrinsicBounds(drawables[i], null, null, null)
} else {
textView[i].setCompoundDrawablesWithIntrinsicBounds(null, null, drawables[i], null)
}
} }
} }
} }
...@@ -98,7 +103,11 @@ object DrawableHelper { ...@@ -98,7 +103,11 @@ object DrawableHelper {
* @see compoundDrawables * @see compoundDrawables
*/ */
fun compoundLeftDrawable(textView: TextView, drawable: Drawable) = fun compoundLeftDrawable(textView: TextView, drawable: Drawable) =
if (textView.resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_LTR) {
textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null) textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
} else {
textView.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null)
}
/** /**
* Compounds a Drawable (to appear on the right side of a text) into a TextView. * Compounds a Drawable (to appear on the right side of a text) into a TextView.
...@@ -108,7 +117,11 @@ object DrawableHelper { ...@@ -108,7 +117,11 @@ object DrawableHelper {
* @see compoundLeftDrawable * @see compoundLeftDrawable
*/ */
fun compoundRightDrawable(textView: TextView, drawable: Drawable) = fun compoundRightDrawable(textView: TextView, drawable: Drawable) =
if (textView.resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_LTR) {
textView.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null) textView.setCompoundDrawablesWithIntrinsicBounds(null, null, drawable, null)
} else {
textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
}
/** /**
* Compounds a Drawable (to appear on the left and right side of a text) into a TextView. * Compounds a Drawable (to appear on the left and right side of a text) into a TextView.
...@@ -123,7 +136,11 @@ object DrawableHelper { ...@@ -123,7 +136,11 @@ object DrawableHelper {
leftDrawable: Drawable, leftDrawable: Drawable,
rightDrawable: Drawable rightDrawable: Drawable
) = ) =
if (textView.resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_LTR) {
textView.setCompoundDrawablesWithIntrinsicBounds(leftDrawable, null, rightDrawable, null) textView.setCompoundDrawablesWithIntrinsicBounds(leftDrawable, null, rightDrawable, null)
} else {
textView.setCompoundDrawablesWithIntrinsicBounds(rightDrawable, null, leftDrawable, null)
}
/** /**
* Returns the user status drawable. * Returns the user status drawable.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment