Skip to content

Commit

Permalink
Fixed tabs being partially dragged accidentally (instead of clicked)
Browse files Browse the repository at this point in the history
  • Loading branch information
JetpackDuba committed Sep 25, 2023
1 parent 59a9b27 commit 81253c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,23 @@ fun RepositoriesTabPanel(
modifier = Modifier
.height(tabsHeight)
.weight(1f, false)
.horizontalDragContainer(dragDropState),
.horizontalDragContainer(
dragDropState = dragDropState,
onDraggedTab = {
val tab = tabs.getOrNull(it)

if (tab != null) {
onTabSelected(tab)
}
},
),
state = stateHorizontal,
) {
itemsIndexed(
items = tabs,
key = { _, tab -> tab.tabViewModel }
) { index, tab ->
HorizontalDraggableItem(dragDropState, index) { isDragged ->
LaunchedEffect(isDragged) {
if (isDragged) {
onTabSelected(tab)
}
}
HorizontalDraggableItem(dragDropState, index) { _ ->
Tooltip(tab.path) {
Tab(
modifier = Modifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ class VerticalDragDropState internal constructor(
}

@Composable
fun Modifier.horizontalDragContainer(dragDropState: HorizontalDragDropState): Modifier {
fun Modifier.horizontalDragContainer(dragDropState: HorizontalDragDropState, onDraggedTab: (Int) -> Unit): Modifier {
val state = rememberDraggableState {
println("Dragging horizontally $it")
dragDropState.onDrag(Offset(it, 0f))
Expand All @@ -302,6 +302,11 @@ fun Modifier.horizontalDragContainer(dragDropState: HorizontalDragDropState): Mo
startDragImmediately = false,
onDragStarted = {
dragDropState.onDragStart(it)
val index = dragDropState.draggingItemIndex

if (index != null) {
onDraggedTab(index)
}
},
onDragStopped = {
println("On drag stopped")
Expand Down

0 comments on commit 81253c0

Please sign in to comment.