Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LazyVerticalGrid - ReorderableItem only animates vertically #176

Open
Monabr opened this issue Oct 9, 2022 · 4 comments
Open

LazyVerticalGrid - ReorderableItem only animates vertically #176

Monabr opened this issue Oct 9, 2022 · 4 comments

Comments

@Monabr
Copy link

Monabr commented Oct 9, 2022

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:

  • kotlin_version = '1.7.20'
  • compose_version = '1.3.0-rc01'
  • kotlinCompilerExtensionVersion = '1.3.2'
  • org.burnoutcrew.composereorderable:reorderable: 0.9.2
@Monabr
Copy link
Author

Monabr commented Oct 9, 2022

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

@wakaztahir
Copy link
Contributor

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
Copy link
Contributor

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

@kmakowski-system1
Copy link

Has anyone solved the problem with moving elements animation ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants