A ratingbar for jetpack compose
Add in project build.gradle:
repositories {
maven { url 'https://jitpack.io' }
}
// App build.gradle
dependencies {
implementation 'com.github.a914-gowtham:compose-ratingbar:1.2.3'
//mavenCentral
// implementation 'io.github.a914-gowtham:compose-ratingbar:1.2.3'
}
import androidx.compose.runtime.*
var rating: Float by remember { mutableStateOf(initialRating) }
RatingBar(
value = rating,
config = RatingBarConfig()
.style(RatingBarStyle.HighLighted),
onValueChange = {
rating = it
},
onRatingChanged = {
Log.d("TAG", "onRatingChanged: $it")
}
)
Ratingbar composable can be customized using RatingBarConfig class as shown below:
RatingBarConfig()
.activeColor(Color.Yellow)
.hideInactiveStars(true)
.inactiveColor(Color.LightGray)
.stepSize(StepSize.HALF)
.numStars(10)
.isIndicator(true)
.size(24.dp)
.padding(6.dp)
.style(RatingBarStyle.HighLighted)
- Current version of the library only supports Stepsize 1f and 0.5f when click or drag. However, Initial Rating value could be any float value like 3.8 etc.
Give a ⭐️ if this project helped you!