🛠️ Fix offset issue with ModalDrawer for RTL languages

* Fixed incorrect offset/animation for Custom Modal Drawer in RTL languages (e.g. Arabic)
This commit is contained in:
Acclorite 2025-02-10 13:25:42 +02:00
parent cd18c430a5
commit 9afcbd237c

View file

@ -35,7 +35,9 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import ua.acclorite.book_story.presentation.core.components.common.AnimatedVisibility
import ua.acclorite.book_story.presentation.core.components.common.LazyColumnWithScrollbar
@ -63,7 +65,9 @@ fun ModalDrawer(
header: @Composable () -> Unit = {},
content: LazyListScope.() -> Unit
) {
val layoutDirection = LocalLayoutDirection.current
val density = LocalDensity.current
val offset = remember { mutableFloatStateOf(0f) }
val offsetDp = remember {
derivedStateOf {
@ -93,8 +97,14 @@ fun ModalDrawer(
) {
AnimatedVisibility(
visible = show,
enter = slideInHorizontally { (-it + with(density) { -20.dp.toPx() }).toInt() },
exit = slideOutHorizontally { (-it + with(density) { -20.dp.toPx() }).toInt() }
enter = slideInHorizontally {
if (layoutDirection == LayoutDirection.Ltr) (-it + with(density) { -20.dp.toPx() }).toInt()
else (it + with(density) { 20.dp.toPx() }).toInt()
},
exit = slideOutHorizontally {
if (layoutDirection == LayoutDirection.Ltr) (-it + with(density) { -20.dp.toPx() }).toInt()
else (it + with(density) { 20.dp.toPx() }).toInt()
}
) {
Column(
modifier = Modifier
@ -125,8 +135,9 @@ fun ModalDrawer(
else offset.floatValue = 0f
}
) { _, dragAmount ->
offset.floatValue = (offset.floatValue + dragAmount)
.coerceAtMost(0f)
offset.floatValue = (if (layoutDirection == LayoutDirection.Ltr) {
offset.floatValue + dragAmount
} else offset.floatValue + (-dragAmount)).coerceAtMost(0f)
}
}
.systemBarsPadding()