Skip to content

Commit 65d48ed

Browse files
authored
Merge pull request #45 from MohamedRejeb/0.3x
Upgrade dependencies: Kotlin to 2.2.0, Compose to 1.8.2, AGP to 8.11.…
2 parents 4bab26d + 33f13fc commit 65d48ed

File tree

22 files changed

+71
-125
lines changed

22 files changed

+71
-125
lines changed

compose-dnd/build.gradle.kts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,12 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
@file:OptIn(ExperimentalWasmDsl::class)
17+
1618
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
1719
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
1820
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
1921

20-
/*
21-
* Copyright 2023, Mohamed Ben Rejeb and the Compose Dnd project contributors
22-
*
23-
* Licensed under the Apache License, Version 2.0 (the "License");
24-
* you may not use this file except in compliance with the License.
25-
* You may obtain a copy of the License at
26-
*
27-
* http://www.apache.org/licenses/LICENSE-2.0
28-
*
29-
* Unless required by applicable law or agreed to in writing, software
30-
* distributed under the License is distributed on an "AS IS" BASIS,
31-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32-
* See the License for the specific language governing permissions and
33-
* limitations under the License.
34-
*/
3522
plugins {
3623
alias(libs.plugins.kotlinMultiplatform)
3724
alias(libs.plugins.androidLibrary)
@@ -62,7 +49,6 @@ kotlin {
6249
browser()
6350
}
6451

65-
@OptIn(ExperimentalWasmDsl::class)
6652
wasmJs {
6753
browser {
6854
testTask {
@@ -88,10 +74,14 @@ kotlin {
8874

8975
android {
9076
namespace = "com.mohamedrejeb.compose.dnd"
91-
compileSdk = libs.versions.android.compileSdk.get().toInt()
77+
compileSdk = libs.versions.android.compileSdk
78+
.get()
79+
.toInt()
9280

9381
defaultConfig {
94-
minSdk = libs.versions.android.minSdk.get().toInt()
82+
minSdk = libs.versions.android.minSdk
83+
.get()
84+
.toInt()
9585
}
9686

9787
compileOptions {

compose-dnd/src/commonMain/kotlin/com/mohamedrejeb/compose/dnd/DragAndDropContainer.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ fun <T> DragAndDropContainer(
6363
modifier = modifier
6464
.onPlaced {
6565
positionInRoot.value = it.positionInRoot()
66-
}
67-
.pointerInput(enabled, state, state.pointerId) {
66+
}.pointerInput(enabled, state, state.pointerId) {
6867
if (!enabled) return@pointerInput
6968

7069
awaitEachGesture {

compose-dnd/src/commonMain/kotlin/com/mohamedrejeb/compose/dnd/DragAndDropState.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,12 @@ import kotlinx.coroutines.launch
4949
fun <T> rememberDragAndDropState(
5050
dragAfterLongPress: Boolean = false,
5151
requireFirstDownUnconsumed: Boolean = false,
52-
): DragAndDropState<T> {
53-
return remember {
52+
): DragAndDropState<T> = remember {
5453
DragAndDropState(
5554
dragAfterLongPress = dragAfterLongPress,
5655
requireFirstDownUnconsumed = requireFirstDownUnconsumed,
5756
)
5857
}
59-
}
6058

6159
/**
6260
* State of the drag and drop
@@ -131,6 +129,10 @@ class DragAndDropState<T>(
131129
internal fun addDraggableItem(
132130
state: DraggableItemState<T>
133131
) {
132+
if (draggableItemMap[state.key] == state) {
133+
return
134+
}
135+
134136
draggableItemMap[state.key] = state
135137
}
136138

@@ -202,8 +204,7 @@ class DragAndDropState<T>(
202204
size2 = it.size,
203205
) &&
204206
(dropTargetIds.isEmpty() || it.key in dropTargetIds)
205-
}
206-
.groupBy { it.zIndex }
207+
}.groupBy { it.zIndex }
207208
.maxByOrNull { it.key }
208209
?.value
209210
.orEmpty()
@@ -220,7 +221,10 @@ class DragAndDropState<T>(
220221
)
221222

222223
if (hoveredDropTarget?.key != hoveredDropTargetKey && newDraggedItemState != null) {
223-
dropTargetMap.values.find { it.key == hoveredDropTargetKey }?.onDragExit?.invoke(newDraggedItemState)
224+
dropTargetMap.values
225+
.find { it.key == hoveredDropTargetKey }
226+
?.onDragExit
227+
?.invoke(newDraggedItemState)
224228
hoveredDropTarget?.onDragEnter?.invoke(newDraggedItemState)
225229
}
226230

compose-dnd/src/commonMain/kotlin/com/mohamedrejeb/compose/dnd/drag/CoreDraggableItem.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,9 @@ internal fun <T> CoreDraggableItem(
127127
modifier = modifier
128128
.onPlaced {
129129
draggableItemState.positionInRoot = it.positionInRoot()
130-
}
131-
.onSizeChanged {
130+
}.onSizeChanged {
132131
draggableItemState.size = it.toSize()
133-
}
134-
.pointerInput(
132+
}.pointerInput(
135133
key,
136134
enabled,
137135
state,

compose-dnd/src/commonMain/kotlin/com/mohamedrejeb/compose/dnd/drag/DraggableItemState.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ internal class DraggableItemState<T>(
3535

3636
var content: @Composable () -> Unit,
3737
) {
38-
fun copy(): DraggableItemState<T> {
39-
return DraggableItemState(
38+
fun copy(): DraggableItemState<T> = DraggableItemState(
4039
key = key,
4140
data = data,
4241
dropTargets = dropTargets,
@@ -47,5 +46,4 @@ internal class DraggableItemState<T>(
4746
size = size,
4847
content = content
4948
)
50-
}
5149
}

compose-dnd/src/commonMain/kotlin/com/mohamedrejeb/compose/dnd/drag/DraggedItemShadow.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@ internal fun <T> DraggedItemShadow(
4646
with(density) {
4747
state.dragSizeAnimatable.value.toDpSize()
4848
}
49-
)
50-
.onPlaced {
49+
).onPlaced {
5150
draggedItemPositionInRoot.value = it.positionInRoot()
52-
}
53-
.graphicsLayer {
51+
}.graphicsLayer {
5452
val dragPositionX = state.dragPositionAnimatable.value.x + state.dragPosition.value.x
5553
val dragPositionY = state.dragPositionAnimatable.value.y + state.dragPosition.value.y
5654
translationX = dragPositionX - draggedItemPositionInRoot.value.x

compose-dnd/src/commonMain/kotlin/com/mohamedrejeb/compose/dnd/drag/DraggedItemState.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ class DraggedItemState<T> internal constructor(
3535
key: Any = this.key,
3636
data: T = this.data,
3737
dragAmount: Offset = this.dragAmount,
38-
): DraggedItemState<T> {
39-
return DraggedItemState(
38+
): DraggedItemState<T> = DraggedItemState(
4039
key = key,
4140
data = data,
4241
dragAmount = dragAmount,
4342
)
44-
}
4543

4644
override fun equals(other: Any?): Boolean {
4745
if (this === other) return true

compose-dnd/src/commonMain/kotlin/com/mohamedrejeb/compose/dnd/drop/DropTarget.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ private data class DropTargetNodeElement<T>(
137137
private data class DropTargetNode<T>(
138138
val dropTargetState: DropTargetState<T>,
139139
var state: DragAndDropState<T>,
140-
) : Modifier.Node(), LayoutAwareModifierNode, CompositionLocalConsumerModifierNode {
140+
) : Modifier.Node(),
141+
LayoutAwareModifierNode,
142+
CompositionLocalConsumerModifierNode {
141143

142144
private val key get() = dropTargetState.key
143145

compose-dnd/src/commonMain/kotlin/com/mohamedrejeb/compose/dnd/reorder/ReorderState.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@ import com.mohamedrejeb.compose.dnd.annotation.ExperimentalDndApi
3030
@Composable
3131
fun <T> rememberReorderState(
3232
dragAfterLongPress: Boolean = false,
33-
): ReorderState<T> {
34-
return remember {
33+
): ReorderState<T> = remember {
3534
ReorderState(
3635
dragAfterLongPress = dragAfterLongPress,
3736
)
3837
}
39-
}
4038

4139
/**
4240
* State of the reorder

compose-dnd/src/commonMain/kotlin/com/mohamedrejeb/compose/dnd/utils/DragGestureUtils.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ internal suspend inline fun AwaitPointerEventScope.awaitPointerSlopOrCancellatio
9696
val inDirection = if (triggerOnMainAxisSlop) {
9797
abs(totalMainPositionChange)
9898
} else {
99-
pointerDirectionConfig.offsetFromChanges(
99+
pointerDirectionConfig
100+
.offsetFromChanges(
100101
totalMainPositionChange,
101102
totalCrossPositionChange
102103
).getDistance()
@@ -174,9 +175,7 @@ private val mouseToTouchSlopRatio = mouseSlop / defaultTouchSlop
174175
// functions public (see the comment at the top of the file).
175176
// After it will be a public API, we should get rid of `touchSlop / 144` and return absolute
176177
// value 0.125.dp.toPx(). It is not possible right now, because we can't access density.
177-
internal fun ViewConfiguration.pointerSlop(pointerType: PointerType): Float {
178-
return when (pointerType) {
178+
internal fun ViewConfiguration.pointerSlop(pointerType: PointerType): Float = when (pointerType) {
179179
PointerType.Mouse -> touchSlop * mouseToTouchSlopRatio
180180
else -> touchSlop
181181
}
182-
}

0 commit comments

Comments
 (0)