a914-gowtham / compose-ratingbar

ratingbar composable for jetpack compose :rocket::star2:
MIT License
240 stars 21 forks source link

Rating does not recompose if rating value changed extrenally #12

Closed vitidev closed 3 years ago

vitidev commented 3 years ago
  @Composable
  fun RatingBar(
      modifier: Modifier = Modifier,
      value: Float = 0f,
      numStars: Int = 5,
      size: Dp = 26.dp,
      padding: Dp = 2.dp,
      isIndicator: Boolean = false,
      activeColor: Color = Color(0xffffd740),
      inactiveColor: Color = Color(0xffffecb3),
      stepSize: StepSize = StepSize.ONE,
      ratingBarStyle: RatingBarStyle = RatingBarStyle.Normal,
      onRatingChanged: (Float) -> Unit
  ) {
      var rowSize by remember { mutableStateOf(Size.Zero) }
      var rating by remember { mutableStateOf(value) }

var rating by remember { mutableStateOf(value) } knows nothing about external changes in value

I'm newbie in jetpack compose, but I guess you need to rewrite the code like this

   var rating by remember(value) { mutableStateOf(value) }
a914-gowtham commented 3 years ago

fixed in the v1.1.1 release. changed to state hoist pattern. so, you can check latest updated readme.