Managing Layout Direction in Jetpack Compose

Managing Layout Direction in Jetpack Compose

Android Sep 9, 2022

I have recently been on the path of learning Jetpack Compose for Android Development. It's excellent to see that UI implementation in Android has evolved.


I'm developing an application named Private. It's a simple Privacy application that uses Jetpack Compose as UI and MVVM as Architecture. for the Password section, I needed to have a Dialog. The application, for now, is just LTR and doesn't support RTL so like in the old days I set supportRtl to false in the Manifest and expect that the application gonna shown in the LTR direction.


But in devices with the RTL languages when a Dialog appears, Everything is RTL and then changes to LTR and unfortunately, the whole transition is visible! So what is the solution?


I've solved this problem with CompositionLocalProvider and LocalLayoutDirection, It's simple:

	onDismissRequest = { },
	properties = DialogProperties(
		dismissOnBackPress = false,
    	dismissOnClickOutside = false
) {
	CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) {
Managing Layout Direction in Jetpack Compose

With this, You can manage Layout Direction with Logic and Provide the best functionality as Users deserve.

Good Luck.


Benyamin Eskandari

Curious, Experienced Android Developer Also in love with Rust, DevOps, and System Programming Trying to read a lot of books and learn a lot of things, I will write posts about my path on this journey.