Skip to content

Commit a0f59c1

Browse files
authored
Merge pull request #125 from lcazalbasu/improvement/update-ontap-event-linechart
Improvement/Replace the onTap gesture from the LineChart with onPress
2 parents 2ed0f02 + ad12ad9 commit a0f59c1

File tree

2 files changed

+15
-29
lines changed

2 files changed

+15
-29
lines changed

compose-charts/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mavenPublishing{
1515
coordinates(
1616
groupId = "io.github.ehsannarmani",
1717
artifactId = "compose-charts",
18-
version = "0.1.8"
18+
version = "0.1.9"
1919
)
2020
pom{
2121
name.set("Compose Charts")

compose-charts/src/commonMain/kotlin/ir/ehsannarmani/compose_charts/LineChart.kt

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -246,29 +246,17 @@ fun LineChart(
246246
linesPathData.clear()
247247
}
248248

249-
var tapJob: Job? = null
250-
var isDisplayingPopup = false
251-
suspend fun hidePopup(
252-
withAnimation: Boolean = true
253-
) {
254-
val duration = if (withAnimation) {
255-
300
256-
} else {
257-
0
258-
}
259-
260-
popupAnimation.animateTo(0f, animationSpec = tween(duration))
249+
suspend fun hidePopup() {
250+
popupAnimation.animateTo(0f, animationSpec = tween(300))
261251
popups.clear()
262252
popupsOffsetAnimators.clear()
263-
isDisplayingPopup = false
264253
}
265254

266255
fun PointerInputScope.showPopup(
267256
data: List<Line>,
268257
size: IntSize,
269258
position: Offset
270259
) {
271-
isDisplayingPopup = true
272260
popups.clear()
273261

274262
data.forEachIndexed { dataIndex, line ->
@@ -336,11 +324,13 @@ fun LineChart(
336324

337325
scope.launch {
338326
if (popupAnimation.value != 1f && !popupAnimation.isRunning) {
339-
popupAnimation.animateTo(1f, animationSpec = tween(500))
327+
popupAnimation.animateTo(1f, animationSpec = popupProperties.animationSpec)
340328
}
341329
}
342330
}
343331

332+
var onPressJob: Job? = null
333+
344334
Column(modifier = modifier) {
345335
if (labelHelperProperties.enabled) {
346336
LabelHelper(
@@ -389,27 +379,23 @@ fun LineChart(
389379
return@pointerInput
390380

391381
detectTapGestures(
392-
onTap = {
393-
if (tapJob != null && tapJob?.isActive == true) {
394-
tapJob?.cancel()
395-
tapJob = null
382+
onPress = {
383+
if (onPressJob?.isActive == true) {
384+
onPressJob?.cancel()
385+
onPressJob = null
396386
}
397387

398-
tapJob = scope.launch {
399-
if (isDisplayingPopup) {
400-
hidePopup(withAnimation = false)
401-
}
402-
388+
onPressJob = scope.launch {
403389
showPopup(
404390
data = data,
405391
size = size,
406392
position = it
407393
)
408394

409-
delay(500)
410-
if (isDisplayingPopup) {
411-
hidePopup(withAnimation = true)
412-
}
395+
tryAwaitRelease()
396+
delay(timeMillis = popupProperties.duration)
397+
398+
hidePopup()
413399
}
414400
},
415401
)

0 commit comments

Comments
 (0)