Skip to content

Commit

Permalink
fix(ui): RTL workaround for SwipeToDismissBox
Browse files Browse the repository at this point in the history
  • Loading branch information
JunkFood02 committed Feb 13, 2024
1 parent 44752b8 commit 6ed42a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions app/src/main/java/me/ash/reader/ui/page/home/flow/ArticleItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import coil.size.Precision
import coil.size.Scale
Expand Down Expand Up @@ -156,7 +158,9 @@ fun ArticleItem(

// Bottom
Row(
modifier = Modifier.fillMaxWidth().padding(top = 4.dp),
modifier = Modifier
.fillMaxWidth()
.padding(top = 4.dp),
) {
// Feed icon
if (articleListFeedIcon.value) {
Expand Down Expand Up @@ -331,9 +335,12 @@ private fun RowScope.SwipeToDismissBoxBackgroundContent(
}
)
}
// FIXME: Remove this once SwipeToDismissBox has proper RTL support
val isRtl = LocalLayoutDirection.current == LayoutDirection.Rtl

val alignment = when (direction) {
SwipeToDismissBoxValue.StartToEnd -> Alignment.CenterStart
SwipeToDismissBoxValue.EndToStart -> Alignment.CenterEnd
SwipeToDismissBoxValue.StartToEnd -> if (isRtl) Alignment.CenterEnd else Alignment.CenterStart
SwipeToDismissBoxValue.EndToStart -> if (isRtl) Alignment.CenterStart else Alignment.CenterEnd
SwipeToDismissBoxValue.Settled -> Alignment.Center
}
val swipeToStartAction = LocalArticleListSwipeStartAction.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,15 @@ fun SwipeToDismissBox(
enableDismissFromEndToStart: Boolean = true,
content: @Composable RowScope.() -> Unit,
) {
val isRtl = LocalLayoutDirection.current == LayoutDirection.Rtl
// val isRtl = LocalLayoutDirection.current == LayoutDirection.Rtl

Box(
modifier
.anchoredDraggable(
state = state.anchoredDraggableState,
orientation = Orientation.Horizontal,
enabled = enabled && state.currentValue == SwipeToDismissBoxValue.Settled,
reverseDirection = isRtl,
// reverseDirection = isRtl,
),
propagateMinConstraints = true
) {
Expand Down

0 comments on commit 6ed42a2

Please sign in to comment.