a914-gowtham / compose-ratingbar

ratingbar composable for jetpack compose :rocket::star2:
MIT License
241 stars 21 forks source link
android-jetpack compose-rating-bar jetpack jetpack-components jetpack-compose jetpack-compose-ratingbar jetpack-ratingbar rating-bar rating-bar-compose ratingbar ratingbar-compose

Compose-Ratingbar

A ratingbar for jetpack compose

Maven Central

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

Show some ❤ and support

Give a ⭐️ if this project helped you!

Buy Me A Coffee