Skip to content

Commit

Permalink
Allow disabling drag and drop runtime (#17)
Browse files Browse the repository at this point in the history
Allow disabling drag and drop runtime
  • Loading branch information
cp-megh-l authored Oct 18, 2024
1 parent a8f6e3a commit 8b5ce0f
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.example.compose_recyclerview

import android.util.Log
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -98,6 +100,11 @@ fun <T> ComposeRecyclerView(
ItemTouchHelperConfig().apply { itemTouchHelperConfig?.invoke(this) }
}

// To disable drag and drop when itemTypeBuilder is null
LaunchedEffect(itemTypeBuilder) {
config.isLongPressDragEnabled = itemTypeBuilder != null
}

val itemTouchHelper = remember {
ItemTouchHelper(object : ItemTouchHelper.SimpleCallback(
config.dragDirs ?: (UP or DOWN or START or END), config.swipeDirs ?: (LEFT or RIGHT)
Expand Down

0 comments on commit 8b5ce0f

Please sign in to comment.