onClick does not occur on onDrag start, and onRelease added that occur on onDrag end

This commit is contained in:
a.kalmakhanov 2022-08-26 16:25:21 +06:00
parent 11b278fc81
commit cd64ecd817
3 changed files with 17 additions and 4 deletions

View File

@ -66,6 +66,12 @@ fun App() {
pointTwo.second + (end.focus.longitude - start.focus.longitude).toDegrees() 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 false// returning false, because when we are dragging circle we don't want to drag map
} else true } else true
},
onRelease = {
println("On drag ended $this")
},
onClick = {
println("On CLick $this")
} }
) )
) { ) {

View File

@ -22,8 +22,9 @@ public data class MapViewConfig(
val onDrag: (start: MapViewPoint, end: MapViewPoint) -> Boolean = { _, _ -> true }, val onDrag: (start: MapViewPoint, end: MapViewPoint) -> Boolean = { _, _ -> true },
val onViewChange: MapViewPoint.() -> Unit = {}, val onViewChange: MapViewPoint.() -> Unit = {},
val onSelect: (GmcBox) -> Unit = {}, val onSelect: (GmcBox) -> Unit = {},
val onRelease: MapViewPoint.() -> Unit = {},
val zoomOnSelect: Boolean = true, val zoomOnSelect: Boolean = true,
val resetViewPoint: Boolean = false val resetViewPoint: Boolean = false,
) )
@Composable @Composable

View File

@ -141,9 +141,6 @@ public actual fun MapView(
selectRect = null selectRect = null
} }
} else { } 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 -> drag(change.id) { dragChange ->
val dragAmount = dragChange.position - dragChange.previousPosition val dragAmount = dragChange.position - dragChange.previousPosition
val dpStart = val dpStart =
@ -174,6 +171,15 @@ public actual fun MapView(
val newViewPoint = viewPoint.zoom(-change.scrollDelta.y.toDouble() * config.zoomSpeed, invariant) val newViewPoint = viewPoint.zoom(-change.scrollDelta.y.toDouble() * config.zoomSpeed, invariant)
config.onViewChange(newViewPoint) config.onViewChange(newViewPoint)
viewPointInternal = 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() }.fillMaxSize()