Closed CiprianGabor closed 1 year ago
You have not added animateplacement modifier to the column, do something like this.
modifier = Modifier .detectReorderAfterLongPress(state) .animateItemPlacement( animationSpec = tween( durationMillis = 100, easing = FastOutSlowInEasing ) )
It does not work either
Hello @warting @aclassen. Any idea why animations and haptic does not work?
this is the function:
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun VerticalReorderList(data: MutableState<List<String>>) {
val haptic = LocalHapticFeedback.current
val state = rememberReorderableLazyListState(onMove = { from, to ->
data.value = data.value.toMutableList().apply {
add(to.index, removeAt(from.index))
}
})
LazyColumn(
state = state.listState,
modifier = Modifier
.reorderable(state)
) {
items(data.value.size, { data.value[it] }) { item ->
ReorderableItem(state, key = item) { isDragging ->
if (isDragging) haptic.performHapticFeedback(
HapticFeedbackType.LongPress
)
val elevation = animateDpAsState(if (isDragging) 46.dp else 0.dp)
Column(
modifier = Modifier
.shadow(elevation.value)
.background(MaterialTheme.colorScheme.surface)
.detectReorderAfterLongPress(state)
.animateItemPlacement( animationSpec = tween( durationMillis = 100, easing = FastOutSlowInEasing ) )
) {
ShowCategoryDivider(data.value[item])
}
}
}
}
}
and I call it like this inside in an AlertDialog:
var categoryList = remember { mutableStateOf(listOf<String>()) }
VerticalReorderList(categoryList)
Can someone help me please?
Can someone help me please?
I'm going to tell you how I solve this issue.
1) I clone this repo to see if it works. works.
2) I copy the simplest part of the dog list in the example. works.
3) I copied the dog list, putting my own part one by one to see what happened. finally, I found the itemsIndexed
will cause no animation issue.
The problem was with the items(size)
function, you have to use items(list)
in order to work.
For anyone potentially reading this with the same problem: For me, it only worked when using itemsIndexed(list)
and providing the index to ReorderableItem(index = index)
. I passed the key before, but for some reason, only when passing the index, the item was considered dragging.
Animation is not working. Any idea? isDraggigng is always false