@@ -4,6 +4,8 @@ import androidx.compose.foundation.gestures.detectDragGesturesAfterLongPress
4
4
import androidx.compose.foundation.gestures.scrollBy
5
5
import androidx.compose.foundation.lazy.grid.LazyGridState
6
6
import androidx.compose.runtime.LaunchedEffect
7
+ import androidx.compose.runtime.getValue
8
+ import androidx.compose.runtime.rememberUpdatedState
7
9
import androidx.compose.ui.Modifier
8
10
import androidx.compose.ui.composed
9
11
import androidx.compose.ui.geometry.Offset
@@ -71,11 +73,13 @@ public fun <Item> Modifier.gridDragSelect(
71
73
if (! enableHaptics) null
72
74
else hapticFeedback ? : GridDragSelectDefaults .hapticsFeedback
73
75
76
+ val currentItems by rememberUpdatedState(items)
77
+
74
78
pointerInput(Unit ) {
75
79
detectDragGesturesAfterLongPress(
76
80
onDragStart = { offset ->
77
81
state.gridState.itemIndexAtPosition(offset)?.let { startIndex ->
78
- val item = items .getOrNull(startIndex)
82
+ val item = currentItems .getOrNull(startIndex)
79
83
if (item != null && state.selected.contains(item).not ()) {
80
84
haptics?.performHapticFeedback(HapticFeedbackType .LongPress )
81
85
state.startDrag(item, startIndex)
@@ -92,7 +96,7 @@ public fun <Item> Modifier.gridDragSelect(
92
96
? : return @whenDragging
93
97
94
98
val newSelection =
95
- items .getSelectedItems(itemPosition, dragState, state::isSelected)
99
+ currentItems .getSelectedItems(itemPosition, dragState, state::isSelected)
96
100
97
101
updateDrag(current = itemPosition)
98
102
updateSelected(newSelection)
0 commit comments