I want to set a direction of a specific composable to be RTL
@Composable
fun ViewToBeChanged() {
Row {
Image()
Column {
Text("Title")
Text("Subtitle")
}
}
}
Is it possible?
Jetpack compose Layout documentation mentions LocalLayoutDirection
Change the layout direction of a composable by changing the
LocalLayoutDirection
compositionLocal.
But I have no idea how to use it in a composable to take effect.
When the state changes, the composable functions are called again with the new data. This causes the UI elements to be redrawn--this process is called recomposition.
Jetpack Compose is built around composable functions. These functions let you define your app's UI programmatically by describing how it should look and providing data dependencies, rather than focusing on the process of the UI's construction (initializing an element, attaching it to a parent, etc.).
Fortunately, Jetpack Compose comes with a bunch of tools to make it easier for developers to build these beautiful, responsive UIs that adapt onto any screen size.
Subcompose layout which allows to subcompose the actual content during the measuring stage for example to use the values calculated during the measurement as params for the composition of the children.
You can use the CompositionLocalProvider
to provide a custom LocalLayoutDirection
.
Something like:
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl ) {
Column(Modifier.fillMaxWidth()) {
Text("Title")
Text("Subtitle")
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With