From 8cfdc59ceb71bf06370fdfd24b8d3bc99750be59 Mon Sep 17 00:00:00 2001 From: gowtham-13309 Date: Thu, 25 Apr 2024 01:17:20 +0530 Subject: [PATCH] fix: onPress not working --- .../src/main/java/com/gowtham/ratingbar/RatingBar.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ratingbar/src/main/java/com/gowtham/ratingbar/RatingBar.kt b/ratingbar/src/main/java/com/gowtham/ratingbar/RatingBar.kt index a3f4e37..8664e19 100644 --- a/ratingbar/src/main/java/com/gowtham/ratingbar/RatingBar.kt +++ b/ratingbar/src/main/java/com/gowtham/ratingbar/RatingBar.kt @@ -98,6 +98,8 @@ internal fun RatingBar( with(density) { size.toPx() } } + var lastPressedStar= 0f + Row(modifier = modifier .onSizeChanged { rowSize = it.toSize() } .pointerInput( @@ -139,7 +141,7 @@ internal fun RatingBar( } .pointerInput(onValueChange) { //handling when click events - detectTapGestures(onTap = { + detectTapGestures(onPress = { if (isIndicator || hideInactiveStars) return@detectTapGestures val dragX = it.x.coerceIn(-1f, rowSize.width) @@ -155,7 +157,9 @@ internal fun RatingBar( calculatedStars = (numOfStars - calculatedStars) + 1 } onValueChange(calculatedStars) - onRatingChanged(calculatedStars) + lastPressedStar= calculatedStars + }, onTap = { + onRatingChanged(lastPressedStar) }) }) { ComposeStars(