Skip to content

Commit

Permalink
Apply spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedRejeb committed Dec 28, 2023
1 parent 8f3b326 commit ef294c5
Show file tree
Hide file tree
Showing 40 changed files with 720 additions and 198 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
include:
- target: allTests
os: ubuntu-latest
# - target: spotlessCheck
# os: ubuntu-latest
- target: spotlessCheck
os: ubuntu-latest
runs-on: ${{ matrix.os }}

steps:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ plugins {
alias(libs.plugins.androidLibrary) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.kotlinAndroid) apply false
alias(libs.plugins.spotless) apply false
// alias(libs.plugins.spotless) apply false
}
15 changes: 15 additions & 0 deletions compose-dnd/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023, Mohamed Ben Rejeb and the Compose Dnd project contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
/*
* Copyright 2023, Mohamed Ben Rejeb and the Compose Dnd project contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mohamedrejeb.compose.dnd

import androidx.compose.foundation.gestures.*
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.drag
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.*
import androidx.compose.ui.input.pointer.changedToUp
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.layout.positionInRoot
import com.mohamedrejeb.compose.dnd.drag.DraggedItemShadow
Expand Down Expand Up @@ -43,8 +59,9 @@ fun <T> DragAndDropContainer(
}
.pointerInput(state, state.pointerId) {
awaitEachGesture {
if (state.pointerId == null)
if (state.pointerId == null) {
awaitPointerEvent()
}

state.pointerId?.let { pointerId ->
if (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
/*
* Copyright 2023, Mohamed Ben Rejeb and the Compose Dnd project contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mohamedrejeb.compose.dnd

import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.AnimationVector2D
import androidx.compose.animation.core.VectorConverter
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.pointer.PointerId
import com.mohamedrejeb.compose.dnd.drop.DropTargetState
import com.mohamedrejeb.compose.dnd.drag.DraggableItem
import com.mohamedrejeb.compose.dnd.drag.DraggableItemState
import com.mohamedrejeb.compose.dnd.drag.DraggedItemState
import com.mohamedrejeb.compose.dnd.drag.DraggableItem
import com.mohamedrejeb.compose.dnd.drop.DropTargetState
import com.mohamedrejeb.compose.dnd.utils.MathUtils
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -44,6 +65,7 @@ class DragAndDropState<T>(
internal val dragAfterLongPress: Boolean = false,
) {
// Drop Target

/**
* Map of [DropTargetState] by key
*/
Expand All @@ -67,6 +89,7 @@ class DragAndDropState<T>(
}

// Draggable Item

/**
* Map of [DraggableItemState] by key
*/
Expand Down Expand Up @@ -96,10 +119,11 @@ class DragAndDropState<T>(
val key = state.key
val oldState = draggableItemMap[key]

if (oldState != null)
if (oldState != null) {
updateDraggableItem(key, state)
else
} else {
draggableItemMap[key] = state
}
}

internal fun removeDraggableItem(key: Any) {
Expand Down Expand Up @@ -225,7 +249,7 @@ class DragAndDropState<T>(

val dropTarget = dropTargetMap.values.find { it.key == hoveredDropTargetKey }

if (dropTarget == null || dropTarget.dropAnimationEnabled)
if (dropTarget == null || dropTarget.dropAnimationEnabled) {
launch {
val dropTopLeft = dropTarget?.getDropTopLeft(currentDraggableItem.size) ?: currentDraggableItem.positionInRoot

Expand All @@ -236,6 +260,7 @@ class DragAndDropState<T>(
animationSpec = currentDraggableItem.dropAnimationSpec,
)
}.join()
}

draggedItem?.let {
dropTarget?.onDrop?.invoke(it)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
/*
* Copyright 2023, Mohamed Ben Rejeb and the Compose Dnd project contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mohamedrejeb.compose.dnd.annotation

@RequiresOptIn(
message = "This API is experimental and is likely to change or to be changed or removed in the future.",
level = RequiresOptIn.Level.WARNING
)
annotation class ExperimentalDndApi
annotation class ExperimentalDndApi
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
/*
* Copyright 2023, Mohamed Ben Rejeb and the Compose Dnd project contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mohamedrejeb.compose.dnd.drag

import androidx.compose.animation.core.AnimationSpec
import androidx.compose.animation.core.SpringSpec
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.input.pointer.pointerInput
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023, Mohamed Ben Rejeb and the Compose Dnd project contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mohamedrejeb.compose.dnd.drag

import com.mohamedrejeb.compose.dnd.DragAndDropState
Expand All @@ -16,14 +31,14 @@ interface DraggableItemScope {
internal class DraggableItemScopeImpl<T>(
val state: DragAndDropState<T>,
override val key: Any,
): DraggableItemScope {
) : DraggableItemScope {
override val isDragging: Boolean
get() = state.draggedItem?.key == key
}

internal class DraggableItemScopeShadowImpl(
override val key: Any,
): DraggableItemScope {
) : DraggableItemScope {
override val isDragging: Boolean
get() = false
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
/*
* Copyright 2023, Mohamed Ben Rejeb and the Compose Dnd project contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mohamedrejeb.compose.dnd.drag

import androidx.compose.animation.core.*
import androidx.compose.animation.core.AnimationSpec
import androidx.compose.animation.core.SpringSpec
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size

Expand All @@ -18,10 +32,4 @@ internal class DraggableItemState<T>(
var size: Size,

val content: @Composable () -> Unit,
) {
// var dragStartPositionInRoot: Offset = positionInRoot
// var dragStartOffset: Offset = positionInRoot
//
// val dragPosition: MutableState<Offset> = mutableStateOf(positionInRoot)
// val dragPositionAnimatable: Animatable<Offset, AnimationVector2D> = Animatable(Offset.Zero, Offset.VectorConverter)
}
)
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023, Mohamed Ben Rejeb and the Compose Dnd project contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mohamedrejeb.compose.dnd.drag

import androidx.compose.foundation.layout.Box
Expand All @@ -12,7 +27,6 @@ import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.layout.positionInRoot
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import com.mohamedrejeb.compose.dnd.DragAndDropState

@Composable
Expand All @@ -27,7 +41,7 @@ internal fun <T> DraggedItemShadow(
Box(
modifier = Modifier
.size(
with (density) {
with(density) {
state.currentDraggableItem?.size?.toDpSize() ?: DpSize.Zero
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023, Mohamed Ben Rejeb and the Compose Dnd project contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mohamedrejeb.compose.dnd.drag

import androidx.compose.runtime.Immutable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2023, Mohamed Ben Rejeb and the Compose Dnd project contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mohamedrejeb.compose.dnd.drop

import androidx.compose.ui.Alignment
Expand Down Expand Up @@ -59,7 +74,7 @@ private data class DropTargetNodeElement<T>(
val onDrop: (state: DraggedItemState<T>) -> Unit,
val onDragEnter: (state: DraggedItemState<T>) -> Unit,
val onDragExit: (state: DraggedItemState<T>) -> Unit,
): ModifierNodeElement<DropTargetNode<T>>() {
) : ModifierNodeElement<DropTargetNode<T>>() {
override fun create(): DropTargetNode<T> = DropTargetNode(
key = key,
state = state,
Expand Down Expand Up @@ -104,7 +119,7 @@ private data class DropTargetNode<T>(
var onDrop: (state: DraggedItemState<T>) -> Unit,
var onDragEnter: (state: DraggedItemState<T>) -> Unit,
var onDragExit: (state: DraggedItemState<T>) -> Unit,
): Modifier.Node(), LayoutAwareModifierNode {
) : Modifier.Node(), LayoutAwareModifierNode {
override fun onPlaced(coordinates: LayoutCoordinates) {
val size = coordinates.size.toSize()
val topLeft = coordinates.positionInRoot()
Expand Down
Loading

0 comments on commit ef294c5

Please sign in to comment.