Skip to content

Commit ec2c7a1

Browse files
committed
Fixed "locked item" handling in sample
1 parent 065b81f commit ec2c7a1

2 files changed

Lines changed: 22 additions & 27 deletions

File tree

android/src/main/kotlin/org/burnoutcrew/android/ui/reorderlist/ReorderGrid.kt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ private fun HorizontalGrid(
6666
verticalArrangement = Arrangement.spacedBy(4.dp),
6767
horizontalArrangement = Arrangement.spacedBy(4.dp),
6868
modifier = modifier
69-
.reorderable(state).height(200.dp)
69+
.reorderable(state)
70+
.height(200.dp)
7071
.detectReorderAfterLongPress(state)
7172
) {
7273
items(vm.cats, { it.key }) { item ->
@@ -98,26 +99,25 @@ private fun VerticalGrid(
9899
contentPadding = PaddingValues(horizontal = 8.dp),
99100
verticalArrangement = Arrangement.spacedBy(4.dp),
100101
horizontalArrangement = Arrangement.spacedBy(4.dp),
101-
modifier = modifier
102-
.reorderable(state)
103-
.detectReorderAfterLongPress(state)
102+
modifier = modifier.reorderable(state)
104103
) {
105104
items(vm.dogs, { it.key }) { item ->
106-
ReorderableItem(state, item.key) { isDragging ->
107-
val elevation = animateDpAsState(if (isDragging) 8.dp else 0.dp)
108-
if (item.isLocked) {
109-
Box(
110-
contentAlignment = Alignment.Center,
111-
modifier = Modifier
112-
.size(100.dp)
113-
.background(MaterialTheme.colors.surface)
114-
) {
115-
Text(item.title)
116-
}
117-
} else {
105+
if (item.isLocked) {
106+
Box(
107+
contentAlignment = Alignment.Center,
108+
modifier = Modifier
109+
.size(100.dp)
110+
.background(MaterialTheme.colors.surface)
111+
) {
112+
Text(item.title)
113+
}
114+
} else {
115+
ReorderableItem(state, item.key) { isDragging ->
116+
val elevation = animateDpAsState(if (isDragging) 8.dp else 0.dp)
118117
Box(
119118
contentAlignment = Alignment.Center,
120119
modifier = Modifier
120+
.detectReorderAfterLongPress(state)
121121
.shadow(elevation.value)
122122
.aspectRatio(1f)
123123
.background(MaterialTheme.colors.primary)

android/src/main/kotlin/org/burnoutcrew/android/ui/reorderlist/ReorderList.kt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,23 @@ import org.burnoutcrew.reorderable.reorderable
4848
@Composable
4949
fun ReorderList(vm: ReorderListViewModel = viewModel()) {
5050
Column {
51-
NewHorizontalReorderList(
51+
HorizontalReorderList(
5252
vm = vm,
5353
modifier = Modifier.padding(vertical = 16.dp),
5454
)
55-
NewVerticalReorderList(vm = vm)
55+
VerticalReorderList(vm = vm)
5656
}
5757
}
5858

59-
6059
@Composable
61-
private fun NewVerticalReorderList(
60+
private fun VerticalReorderList(
6261
modifier: Modifier = Modifier,
6362
vm: ReorderListViewModel,
6463
) {
6564
val state = rememberReorderableLazyListState(onMove = vm::moveDog, canDragOver = vm::isDogDragEnabled)
6665
LazyColumn(
6766
state = state.listState,
68-
modifier = modifier
69-
.then(
70-
Modifier
71-
.reorderable(state)
72-
.detectReorderAfterLongPress(state)
73-
)
67+
modifier = modifier.reorderable(state)
7468
) {
7569
items(vm.dogs, { item -> item.key }) { item ->
7670
ReorderableItem(state, item.key) { dragging ->
@@ -89,6 +83,7 @@ private fun NewVerticalReorderList(
8983
} else {
9084
Column(
9185
modifier = Modifier
86+
.detectReorderAfterLongPress(state)
9287
.shadow(elevation.value)
9388
.fillMaxWidth()
9489
.background(MaterialTheme.colors.surface)
@@ -106,7 +101,7 @@ private fun NewVerticalReorderList(
106101
}
107102

108103
@Composable
109-
private fun NewHorizontalReorderList(
104+
private fun HorizontalReorderList(
110105
vm: ReorderListViewModel,
111106
modifier: Modifier = Modifier,
112107
) {

0 commit comments

Comments
 (0)