Skip to content

Commit 93d0916

Browse files
committed
Replaced the while(true) loop and awaitPointerEventScope in the pointer input modifier with a more concise detectTapGestures onPress handler.
1 parent 24bc4ed commit 93d0916

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

  • android_app/app/src/main/java/com/health/openscale/ui/screen/components

android_app/app/src/main/java/com/health/openscale/ui/screen/components/PeriodChart.kt

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import android.R.attr.textSize
2121
import android.text.Layout
2222
import android.text.TextUtils
2323
import android.util.Log
24+
import androidx.compose.foundation.gestures.detectTapGestures
2425
import androidx.compose.foundation.layout.padding
2526
import androidx.compose.material3.MaterialTheme
2627
import androidx.compose.runtime.Composable
@@ -169,24 +170,22 @@ fun PeriodChart(
169170
chart = chart,
170171
modelProducer = modelProducer,
171172
modifier = modifier.pointerInput(data) {
172-
while (true) {
173-
awaitPointerEventScope {
174-
val event = awaitPointerEvent()
175-
if (event.changes.all { it.changedToUp() }) {
176-
hoveredIndex?.let { index ->
177-
if (index in data.indices) {
178-
val clickedData = data[index]
179-
// Toggle selection
180-
if (clickedData == selectedPeriod) {
181-
onPeriodClick(null)
182-
} else {
183-
onPeriodClick(clickedData)
184-
}
173+
detectTapGestures(
174+
onPress = {
175+
awaitRelease()
176+
hoveredIndex?.let { index ->
177+
if (index in data.indices) {
178+
val clickedData = data[index]
179+
// Toggle selection
180+
if (clickedData == selectedPeriod) {
181+
onPeriodClick(null)
182+
} else {
183+
onPeriodClick(clickedData)
185184
}
186185
}
187186
}
188187
}
189-
}
188+
)
190189
}
191190
)
192191
}

0 commit comments

Comments
 (0)