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.

Problem

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.

0:00
/

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?

Solution

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

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

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

Good Luck.

Tags

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.