Compose RatingBar

251 stars
by Gowtham

A customizable rating bar component for Jetpack Compose with support for half ratings and custom shapes.

View on GitHub

Documentation

Compose-Ratingbar

A ratingbar for jetpack compose

Download

Add in project build.gradle:

repositories {
    maven { url 'https://jitpack.io' }
}

// App build.gradle
dependencies {
   implementation 'com.github.a914-gowtham:compose-ratingbar:1.3.12'
  //mavenCentral
  // implementation 'io.github.a914-gowtham:compose-ratingbar:1.2.3'

}

Usage

   import androidx.compose.runtime.*

   var rating: Float by remember { mutableStateOf(3.2f) }

   RatingBar(
       value = rating,
       style = RatingBarStyle.Fill(),
       onValueChange = {
           rating = it
       },
       onRatingChanged = {
           Log.d("TAG", "onRatingChanged: $it")
       }
   )

Other optional params:

  fun RatingBar(
      value: Float,
      modifier: Modifier = Modifier,
      numOfStars: Int = 5,
      size: Dp = 32.dp,
      spaceBetween: Dp = 6.dp,
      isIndicator: Boolean = false,
      stepSize: StepSize = StepSize.ONE,
      hideInactiveStars: Boolean = false,
      style: RatingBarStyle,
      onValueChange: (Float) -> Unit,
      onRatingChanged: (Float) -> Unit
)

More Customization✨

Icon can be changed using painterEmpty painterFilled params.

        RatingBar(
            value = rating,
            painterEmpty = painterResource(id = R.drawable.icon_empty),
            painterFilled = painterResource(id = R.drawable.icon_filled),
            onValueChange = {
                rating = it
            },
            onRatingChanged = {
                Log.d("TAG", "onRatingChanged: $it")
            }
        )

Library Info

  • 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.

Show some ❤ and support

Give a ⭐️ if this project helped you!

Dispatch Newsletter
Be the first to discover new Compose libraries
Curated Insights
Digest in 5 minutes or less
Android Analysis
Entertaining takes on happenings
Insider Tips
From top Android developers
Hidden Gems
You won't find elsewhere
"
"Dispatch is truly a newsletter, not just a digest of links. Vinay adds a delightful touch of humor and personality to a thoughtful analysis of the Android happenings of the month. I always learn something just by skimming it that makes me want to bookmark the issue now and dig deeper later."
Zach Klippenstein
ex-Jetpack Compose Team @ Google, Square, Amazon
Join thousands of Android devs who look forward to Dispatch every week