From 9afcbd237cefe33b3356c16cfdc5993f0d5d94d6 Mon Sep 17 00:00:00 2001 From: Acclorite <140836141+Acclorite@users.noreply.github.com> Date: Mon, 10 Feb 2025 13:25:42 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=EF=B8=8F=20Fix=20offset=20issue=20?= =?UTF-8?q?with=20ModalDrawer=20for=20RTL=20languages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixed incorrect offset/animation for Custom Modal Drawer in RTL languages (e.g. Arabic) --- .../components/modal_drawer/ModalDrawer.kt | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/ua/acclorite/book_story/presentation/core/components/modal_drawer/ModalDrawer.kt b/app/src/main/java/ua/acclorite/book_story/presentation/core/components/modal_drawer/ModalDrawer.kt index 1401922a..911a18df 100644 --- a/app/src/main/java/ua/acclorite/book_story/presentation/core/components/modal_drawer/ModalDrawer.kt +++ b/app/src/main/java/ua/acclorite/book_story/presentation/core/components/modal_drawer/ModalDrawer.kt @@ -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()