julioromano
04/01/2021, 3:34 PMRow
to invert the order it lays out its content? (e.g. LTR instead of RTL)Zach Klippenstein (he/him) [MOD]
04/01/2021, 3:36 PMjulioromano
04/01/2021, 3:36 PMjulioromano
04/01/2021, 3:38 PMLayoutDirection
would be great, but can it be done for that Row
only?Zach Klippenstein (he/him) [MOD]
04/01/2021, 3:38 PMjulioromano
04/01/2021, 3:39 PMjulioromano
04/01/2021, 3:40 PMZach Klippenstein (he/him) [MOD]
04/01/2021, 3:42 PMval originalDirection = LocalLayoutDirection.current
val flippedDirection = if (originalDirection == Ltr) Rtl else Ltr
CompositionLocalProvider(LocalLayoutDirection provides flippedDirection) {
Row(…) {
CompositionLocalProvider(LocalLayoutDirection provides originalDirection) {
// Row children here
}
}
}
julioromano
04/01/2021, 3:43 PMZach Klippenstein (he/him) [MOD]
04/01/2021, 3:46 PMRow
if you needed to reuse it lotsjulioromano
04/01/2021, 4:07 PM@Composable
fun InvertibleRow(
isInverted: Boolean,
modifier: Modifier = Modifier,
horizontalArrangement: Arrangement.Horizontal = Arrangement.Start,
verticalAlignment: Alignment.Vertical = <http://Alignment.Top|Alignment.Top>,
content: @Composable RowScope.() -> Unit
) {
val layoutDirection: LayoutDirection = LocalLayoutDirection.current
CompositionLocalProvider(
LocalLayoutDirection provides if (isInverted) layoutDirection.invert() else layoutDirection
) {
Row(
modifier = modifier,
horizontalArrangement = horizontalArrangement,
verticalAlignment = verticalAlignment
) {
CompositionLocalProvider(LocalLayoutDirection provides layoutDirection) {
content()
}
}
}
}
private fun LayoutDirection.invert(): LayoutDirection = when (this) {
LayoutDirection.Ltr -> LayoutDirection.Rtl
LayoutDirection.Rtl -> LayoutDirection.Ltr
}
Vinay Gaba
04/01/2021, 5:29 PMcb
04/02/2021, 8:46 AMLazyRow
and reverseLayout
. This honors the layout direction: LazyRow(reverseLayout = true)