Fix favorites reorder sheet in RTL languages

Fix #637
This commit is contained in:
MM20 2023-12-29 19:04:16 +01:00
parent 54f5bb9a27
commit 0bfdd1484f
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
2 changed files with 10 additions and 18 deletions

View File

@ -12,7 +12,6 @@ import androidx.compose.ui.hapticfeedback.HapticFeedback
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.unit.*
import androidx.compose.ui.zIndex
import de.mm20.launcher2.ui.ktx.animateTo
@ -178,7 +177,6 @@ fun LazyVerticalDragAndDropGrid(
columns,
modifier.dragAndDrop(
state,
LocalLayoutDirection.current == LayoutDirection.Rtl,
LocalHapticFeedback.current
),
state.gridState,
@ -208,7 +206,6 @@ fun LazyHorizontalDragAndDropGrid(
rows,
modifier.dragAndDrop(
state,
LocalLayoutDirection.current == LayoutDirection.Rtl,
LocalHapticFeedback.current
),
state.gridState,
@ -224,7 +221,6 @@ fun LazyHorizontalDragAndDropGrid(
fun Modifier.dragAndDrop(
state: LazyDragAndDropGridState,
isRtl: Boolean,
hapticFeedback: HapticFeedback
) =
this then pointerInput(null) {
@ -235,10 +231,7 @@ fun Modifier.dragAndDrop(
onDragStart = { offset ->
val draggedItem = state.gridState.layoutInfo.visibleItemsInfo.find {
Rect(
it.offset.toOffset().let {off ->
if (isRtl) off.copy(x = state.gridState.layoutInfo.viewportSize.width - off.x - it.size.width)
else off
},
it.offset.toOffset(),
it.size.toSize()
).contains(offset)
}
@ -250,10 +243,7 @@ fun Modifier.dragAndDrop(
val absPosition = state.draggedItemAbsolutePosition
val draggedItem = state.draggedItem
if (absPosition != null && draggedItem != null) {
state.draggedItemAbsolutePosition = absPosition + dragAmount.let {
if (isRtl) it.copy(x = -it.x)
else it
}
state.draggedItemAbsolutePosition = absPosition + dragAmount
val draggedCenter = Rect(absPosition, draggedItem.size.toSize()).center
val dragOver = state.gridState.layoutInfo.visibleItemsInfo.find {
Rect(
@ -308,7 +298,7 @@ fun LazyGridItemScope.DraggableItem(
modifier = modifier
.then(if (isDragged) Modifier else Modifier.animateItemPlacement())
.zIndex(if (isDragged) 1f else 0f)
.offset {
.absoluteOffset {
if (state.draggedItem?.key == key) {
state.draggedItemOffset?.toIntOffset() ?: IntOffset.Zero
} else if (state.droppedItemKey == key) {

View File

@ -1,8 +1,6 @@
package de.mm20.launcher2.ui.launcher.sheets
import android.app.Activity
import android.content.Context
import android.content.pm.LauncherApps
import android.util.Log
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.IntentSenderRequest
@ -33,7 +31,6 @@ import androidx.compose.material.icons.rounded.Delete
import androidx.compose.material.icons.rounded.Settings
import androidx.compose.material.icons.rounded.Tag
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Divider
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.FilledTonalIconButton
@ -65,12 +62,13 @@ import androidx.compose.ui.graphics.drawOutline
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.platform.LocalLifecycleOwner
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.Density
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.toOffset
import androidx.compose.ui.unit.toSize
@ -173,6 +171,7 @@ fun ReorderFavoritesGrid(viewModel: EditFavoritesSheetVM, paddingValues: Padding
val tagsListState = rememberLazyListState()
val tagsTitleSize = 48.dp.toPixels()
val tagsSpacing = 12.dp.toPixels()
val isRtl = LocalLayoutDirection.current == LayoutDirection.Rtl
val state = rememberLazyDragAndDropGridState(
gridState = gridState,
onDragStart = {
@ -200,8 +199,11 @@ fun ReorderFavoritesGrid(viewModel: EditFavoritesSheetVM, paddingValues: Padding
&& hoveredItem.offset.y + tagsTitleSize < position.y
) {
val scroll = tagsListState.layoutInfo.viewportStartOffset
val relCenter =
if (isRtl) draggedCenter.copy(x = tagsListState.layoutInfo.viewportSize.width - draggedCenter.x)
else draggedCenter
val tag = tagsListState.layoutInfo.visibleItemsInfo.find {
draggedCenter.x + scroll > it.offset && draggedCenter.x + scroll < it.offset + it.size - tagsSpacing
relCenter.x + scroll > it.offset && relCenter.x + scroll < it.offset + it.size - tagsSpacing
}
hoveredTag = tag?.index?.let { pinnedTags[it].tag }
} else {