From cd64ecd817a187bf860b6064a764b98bae074351 Mon Sep 17 00:00:00 2001 From: "a.kalmakhanov" Date: Fri, 26 Aug 2022 16:25:21 +0600 Subject: [PATCH] onClick does not occur on onDrag start, and onRelease added that occur on onDrag end --- demo/maps/src/jvmMain/kotlin/Main.kt | 6 ++++++ .../kotlin/center/sciprog/maps/compose/MapView.kt | 3 ++- .../kotlin/center/sciprog/maps/compose/MapViewJvm.kt | 12 +++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/demo/maps/src/jvmMain/kotlin/Main.kt b/demo/maps/src/jvmMain/kotlin/Main.kt index 9660683..1e0634e 100644 --- a/demo/maps/src/jvmMain/kotlin/Main.kt +++ b/demo/maps/src/jvmMain/kotlin/Main.kt @@ -66,6 +66,12 @@ fun App() { pointTwo.second + (end.focus.longitude - start.focus.longitude).toDegrees() false// returning false, because when we are dragging circle we don't want to drag map } else true + }, + onRelease = { + println("On drag ended $this") + }, + onClick = { + println("On CLick $this") } ) ) { diff --git a/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapView.kt b/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapView.kt index 0dc4fd4..5cd3490 100644 --- a/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapView.kt +++ b/maps-kt-compose/src/commonMain/kotlin/center/sciprog/maps/compose/MapView.kt @@ -22,8 +22,9 @@ public data class MapViewConfig( val onDrag: (start: MapViewPoint, end: MapViewPoint) -> Boolean = { _, _ -> true }, val onViewChange: MapViewPoint.() -> Unit = {}, val onSelect: (GmcBox) -> Unit = {}, + val onRelease: MapViewPoint.() -> Unit = {}, val zoomOnSelect: Boolean = true, - val resetViewPoint: Boolean = false + val resetViewPoint: Boolean = false, ) @Composable diff --git a/maps-kt-compose/src/jvmMain/kotlin/center/sciprog/maps/compose/MapViewJvm.kt b/maps-kt-compose/src/jvmMain/kotlin/center/sciprog/maps/compose/MapViewJvm.kt index 27f9496..5dec7ea 100644 --- a/maps-kt-compose/src/jvmMain/kotlin/center/sciprog/maps/compose/MapViewJvm.kt +++ b/maps-kt-compose/src/jvmMain/kotlin/center/sciprog/maps/compose/MapViewJvm.kt @@ -141,9 +141,6 @@ public actual fun MapView( selectRect = null } } else { - val dragStart = change.position - val dpPos = DpOffset(dragStart.x.toDp(), dragStart.y.toDp()) - config.onClick(MapViewPoint(dpPos.toGeodetic(), viewPoint.zoom)) drag(change.id) { dragChange -> val dragAmount = dragChange.position - dragChange.previousPosition val dpStart = @@ -174,6 +171,15 @@ public actual fun MapView( val newViewPoint = viewPoint.zoom(-change.scrollDelta.y.toDouble() * config.zoomSpeed, invariant) config.onViewChange(newViewPoint) viewPointInternal = newViewPoint + }.onPointerEvent(PointerEventType.Release) { + val change = it.changes.first() + val (xPos, yPos) = change.position + val dpOffset = DpOffset(xPos.toDp(), yPos.toDp()) + config.onRelease(MapViewPoint(dpOffset.toGeodetic(), viewPoint.zoom)) + }.onPointerEvent(PointerEventType.Press) { + val dragStart = it.changes.first().position + val dpPos = DpOffset(dragStart.x.toDp(), dragStart.y.toDp()) + config.onClick(MapViewPoint(dpPos.toGeodetic(), viewPoint.zoom)) }.fillMaxSize() -- 2.34.1