aclassen / ComposeReorderable

Enables reordering by drag and drop in Jetpack Compose (Desktop) LazyList & LazyGrid.
Apache License 2.0
836 stars 89 forks source link

LazyVerticalGrid - ReorderableItem only animates vertically #176

Open Monabr opened 2 years ago

Monabr commented 2 years ago

Hi. You have a great library, but I ran into a problem. When trying to drag an element in a LazyVerticalGrid, the animation only happens vertically and not horizontally. However, if you drag an element horizontally, it will change its position, but without animation. It feels like each element is in a column and cannot fly freely. Here is a sample code.

    val data = remember { mutableStateOf(List(100) { "Item $it" }) }
    val state = rememberReorderableLazyGridState(onMove = { from, to ->
        data.value = data.value.toMutableList().apply {
            add(to.index, removeAt(from.index))
        }
    }, canDragOver = {true})
    LazyVerticalGrid(
        columns = Fixed(4),
        state = state.gridState,
        contentPadding = PaddingValues(horizontal = 8.dp),
        verticalArrangement = Arrangement.spacedBy(4.dp),
        horizontalArrangement = Arrangement.spacedBy(4.dp),
        modifier = Modifier
            .reorderable(state)
            .detectReorderAfterLongPress(state)
    ) {
        items(data.value, { it }) { item ->
            ReorderableItem(state, item, defaultDraggingModifier = Modifier.animateItemPlacement()) { isDragging ->
                val elevation = animateDpAsState(if (isDragging) 8.dp else 0.dp)
                Box(
                    contentAlignment = Alignment.Center,
                    modifier = Modifier
                        .shadow(elevation.value)
                        .aspectRatio(1f)
                        .background(MaterialTheme.colors.primary)
                ) {
                    Text(item)
                }
            }
        }
    }

My library versions:

Monabr commented 2 years ago

For somehow if I manually use orientationLocked = false problem is solving.

wakaztahir commented 2 years ago

I have same code , when you lift the item up , it doesn't show that item is being lifted and when you place the item (invisible) at your desired place , it just shows up there , like in a snap , without any animation or anything. Any way the only change is that I use Material3 and it doesn't work with both LazyGrid and Lazy List.

wakaztahir commented 1 year ago

By the way this happened after I upgraded to new version which required me to put a generic parameter everywhere

kmakowski-system1 commented 1 year ago

Has anyone solved the problem with moving elements animation ?