Skip to content

Commit

Permalink
fix: onPress not working
Browse files Browse the repository at this point in the history
  • Loading branch information
gowtham-13309 committed Apr 24, 2024
1 parent 6b248db commit 8cfdc59
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ratingbar/src/main/java/com/gowtham/ratingbar/RatingBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ internal fun RatingBar(
with(density) { size.toPx() }
}

var lastPressedStar= 0f

Row(modifier = modifier
.onSizeChanged { rowSize = it.toSize() }
.pointerInput(
Expand Down Expand Up @@ -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)
Expand All @@ -155,7 +157,9 @@ internal fun RatingBar(
calculatedStars = (numOfStars - calculatedStars) + 1
}
onValueChange(calculatedStars)
onRatingChanged(calculatedStars)
lastPressedStar= calculatedStars
}, onTap = {
onRatingChanged(lastPressedStar)
})
}) {
ComposeStars(
Expand Down

0 comments on commit 8cfdc59

Please sign in to comment.