From f8f9d9622b20a0b3431872a2b8f5848207778231 Mon Sep 17 00:00:00 2001 From: Andrey Ananiev Date: Tue, 5 Dec 2023 20:34:16 +0300 Subject: [PATCH] The marker remains visible after touching the graph. The marker label can be set to null. --- .../compose/extension/ModifierExtensions.kt | 29 +++++-------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/vico/compose/src/main/java/com/patrykandpatrick/vico/compose/extension/ModifierExtensions.kt b/vico/compose/src/main/java/com/patrykandpatrick/vico/compose/extension/ModifierExtensions.kt index 7043bff27..143334f31 100644 --- a/vico/compose/src/main/java/com/patrykandpatrick/vico/compose/extension/ModifierExtensions.kt +++ b/vico/compose/src/main/java/com/patrykandpatrick/vico/compose/extension/ModifierExtensions.kt @@ -17,7 +17,6 @@ package com.patrykandpatrick.vico.compose.extension import androidx.compose.foundation.gestures.Orientation -import androidx.compose.foundation.gestures.detectHorizontalDragGestures import androidx.compose.foundation.gestures.scrollable import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset @@ -42,17 +41,18 @@ internal fun Modifier.chartTouchEvent( if (setTouchPoint != null) { pointerInput(setTouchPoint) { awaitPointerEventScope { - var isDragStarted = false + var isNoDrag = true while (true) { val event = awaitPointerEvent() when (event.type) { - PointerEventType.Move -> isDragStarted = true - PointerEventType.Scroll -> isDragStarted = true + PointerEventType.Press -> setTouchPoint(null) + PointerEventType.Move -> isNoDrag = false PointerEventType.Release -> { - if (!isDragStarted) setTouchPoint( - event.changes.first().position.point - ) - isDragStarted = false + if (isNoDrag) { + setTouchPoint(event.changes.first().position.point) + } else { + isNoDrag = true + } } } } @@ -62,19 +62,6 @@ internal fun Modifier.chartTouchEvent( Modifier }, ) - .then( - if (!isScrollEnabled && setTouchPoint != null) { - pointerInput(setTouchPoint) { - detectHorizontalDragGestures( - onDragStart = { }, - onDragEnd = { }, - onDragCancel = { }, - ) { _, _ -> } - } - } else { - Modifier - }, - ) .then( if (isScrollEnabled && onZoom != null) { pointerInput(setTouchPoint, onZoom) {