Skip to content

Instantly share code, notes, and snippets.

@L-Briand
Created July 18, 2021 09:10
Show Gist options
  • Save L-Briand/045418aa9d2d256702b1dcabbbd1b172 to your computer and use it in GitHub Desktop.
Save L-Briand/045418aa9d2d256702b1dcabbbd1b172 to your computer and use it in GitHub Desktop.
Android View.isLeftToRight()
val View.isLeftToRight: Boolean
@SuppressLint("SwitchIntDef")
get() = when (ViewCompat.getLayoutDirection(this)) {
View.LAYOUT_DIRECTION_LTR -> true
View.LAYOUT_DIRECTION_RTL -> false
View.LAYOUT_DIRECTION_INHERIT -> (parent as? View)?.isLeftToRight ?: true
View.LAYOUT_DIRECTION_LOCALE -> TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_LTR
else -> throw IllegalStateException()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment