a914-gowtham / compose-ratingbar Goto Github PK
View Code? Open in Web Editor NEWA ratingbar composable for jetpack compose :rocket::star2:
License: MIT License
A ratingbar composable for jetpack compose :rocket::star2:
License: MIT License
Currently when the Rating bar is used in a RTL layout the row of stars is correctly switched from LTR to RTL but each individual star has a LTR layout.
Surface in RatingBar is not transparent and I don't understand how to make it transparent. It looks like need to make an additional backgroundColor parameter.
Hello, Trying to install in Gradle.kts but have an error: Failed to resolve: com.github.a914-gowtham:compose-ratingbar:1.1.0
repositories {
maven{
url = uri("https://jitpack.io")
}
google()
mavenCentral()
}
implementation ("com.github.a914-gowtham:compose-ratingbar:1.1.0")
Maven page says it should be
implementation("io.github.a914-gowtham:compose-ratingbar:1.1.0")
The rating value computation function is very sensitive to padding.
When padding is 3.dp - everything is fine
But if the padding is large, then
for example
var rating: Float by rememberSaveable { mutableStateOf(0f) }
Column() {
Text(text = rating.toString())
RatingBar(
value = rating,
size = 20.dp,
padding = 30.dp,
numStars = 3,
ratingBarStyle = RatingBarStyle.HighLighted,
onRatingChanged = {
rating=it
})
}
max value is 9
Could not find com.github.a91gowtham:compose-ratingbar:1.0.9
@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) }
When using RatingBar library with compose version 1.0.0-beta08 I get the following runtime exception:
java.lang.NoSuchMethodError: No static method drawPath-3IgeMak$default(Landroidx/compose/ui/graphics/drawscope/DrawScope;Landroidx/compose/ui/graphics/Path;JFLandroidx/compose/ui/graphics/drawscope/DrawStyle;Landroidx/compose/ui/graphics/ColorFilter;Landroidx/compose/ui/graphics/BlendMode;ILjava/lang/Object;)V in class Landroidx/compose/ui/graphics/drawscope/DrawScope$DefaultImpls; or its super classes (declaration of 'androidx.compose.ui.graphics.drawscope.DrawScope$DefaultImpls' appears in /data/app/~~lPHkKeaVkTN6BDFdaohwwA==/com.steleot.jetpackcompose.playground-sSgRla-zZWCVDMLEPvKzFg==/base.apk)
at com.gowtham.ratingbar.RatingStarKt$FilledStar$1$1.invoke(RatingStar.kt:43)
at com.gowtham.ratingbar.RatingStarKt$FilledStar$1$1.invoke(RatingStar.kt:40)
at androidx.compose.ui.draw.DrawBackgroundModifier.draw(DrawModifier.kt:101)
at androidx.compose.ui.node.ModifiedDrawNode.performDraw(ModifiedDrawNode.kt:102)
at androidx.compose.ui.node.LayoutNodeWrapper$invoke$1.invoke(LayoutNodeWrapper.kt:260)
at androidx.compose.ui.node.LayoutNodeWrapper$invoke$1.invoke(LayoutNodeWrapper.kt:259)
...
Thanks
I think that the padding
parameter should be used only between stars, not all around. To pass a padding for the container a modifier provided by the user should be used instead
We should also move the onRatingChanged
lambda parameter at the end, so that it can be passed as trailing lambda
Not use pointerInput(Unit), It captures the lambda with all the variables inside.
Use, for example, pointerInput(onValueChange).
I spent a day trying to figure out why the new version stopped selecting ratings in some cases.
Description of a similar problem:
https://stackoverflow.com/questions/70849243/listeners-inside-detecttapgestures-only-ever-get-the-first-variable-value-othe
Hey this rating bar is amazing but I am facing an issue with it.
PROBLEM -> I have added the rating bar to a column with vertical scroll, I want that if the user scrolls vertically even on the rating bar nothing should happen to the rating and the column should scroll normally. But right now as soon as we touch the rating bar the rating changes.
Is there any way to achieve this?
Please add a parameter showInactiveStars: Boolean = true
to hide inactive stars.
In indicator mode, they are not always needed, but they take resources
Log
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.olabode.wilson.moovy, PID: 9353
java.lang.IllegalArgumentException: Can't represent a size of 2147483647 in Constraints
at androidx.compose.ui.unit.Constraints$Companion.bitsNeedForSize(Constraints.kt:404)
at androidx.compose.ui.unit.Constraints$Companion.createConstraints-Zbe2FdA$ui_unit_release(Constraints.kt:364)
at androidx.compose.ui.unit.ConstraintsKt.Constraints(Constraints.kt:434)
at androidx.compose.foundation.layout.SizeModifier.getTargetConstraints-OenEA2s(Size.kt:674)
at androidx.compose.foundation.layout.SizeModifier.measure-3p2s80s(Size.kt:690)
at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:37)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:95)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:94)
at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:121)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:75)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_release(OwnerSnapshotObserver.kt:63)
at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:94)
at androidx.compose.ui.node.OuterMeasurablePlaceable.measure-BRTryo0(OuterMeasurablePlaceable.kt:68)
at androidx.compose.ui.node.LayoutNode.measure-BRTryo0(LayoutNode.kt:1172)
at androidx.compose.foundation.layout.BoxKt$boxMeasurePolicy$1.measure-3p2s80s(Box.kt:111)
at androidx.compose.foundation.layout.BoxWithConstraintsKt$BoxWithConstraints$1$1.invoke-0kLqBqw(BoxWithConstraints.kt:62)
at androidx.compose.foundation.layout.BoxWithConstraintsKt$BoxWithConstraints$1$1.invoke(BoxWithConstraints.kt:59)
at androidx.compose.ui.layout.SubcomposeLayoutState$createMeasurePolicy$1.measure-3p2s80s(SubcomposeLayout.kt:212)
at androidx.compose.ui.node.InnerPlaceable.measure-BRTryo0(InnerPlaceable.kt:45)
at androidx.compose.ui.graphics.SimpleGraphicsLayerModifier.measure-3p2s80s(GraphicsLayerModifier.kt:213)
at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:37)
at androidx.compose.foundation.layout.AspectRatioModifier.measure-3p2s80s(AspectRatio.kt:89)
at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:37)
at androidx.compose.foundation.layout.FillModifier.measure-3p2s80s(Size.kt:650)
at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:37)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:95)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:94)
at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:121)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:75)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_release(OwnerSnapshotObserver.kt:63)
at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:94)
at androidx.compose.ui.node.OuterMeasurablePlaceable.measure-BRTryo0(OuterMeasurablePlaceable.kt:68)
at androidx.compose.ui.node.LayoutNode.measure-BRTryo0(LayoutNode.kt:1172)
at androidx.compose.foundation.layout.RowColumnImplKt$rowColumnMeasurePolicy$1.measure-3p2s80s(RowColumnImpl.kt:89)
at androidx.compose.ui.node.InnerPlaceable.measure-BRTryo0(InnerPlaceable.kt:45)
at androidx.compose.foundation.layout.WrapContentModifier.measure-3p2s80s(Size.kt:819)
at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:37)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:95)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:94)
E/AndroidRuntime: at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:121)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:75)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_release(OwnerSnapshotObserver.kt:63)
at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:94)
at androidx.compose.ui.node.OuterMeasurablePlaceable.measure-BRTryo0(OuterMeasurablePlaceable.kt:68)
at androidx.compose.ui.node.LayoutNode.measure-BRTryo0(LayoutNode.kt:1172)
at androidx.compose.foundation.layout.RowColumnImplKt$rowColumnMeasurePolicy$1.measure-3p2s80s(RowColumnImpl.kt:89)
at androidx.compose.ui.node.InnerPlaceable.measure-BRTryo0(InnerPlaceable.kt:45)
at androidx.compose.foundation.ScrollingLayoutModifier.measure-3p2s80s(Scroll.kt:323)
at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:37)
at androidx.compose.ui.graphics.SimpleGraphicsLayerModifier.measure-3p2s80s(GraphicsLayerModifier.kt:213)
at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:37)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:108)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:108)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:108)
at androidx.compose.ui.node.DelegatingLayoutNodeWrapper.measure-BRTryo0(DelegatingLayoutNodeWrapper.kt:108)
at androidx.compose.foundation.layout.FillModifier.measure-3p2s80s(Size.kt:650)
at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:37)
at androidx.compose.foundation.layout.FillModifier.measure-3p2s80s(Size.kt:650)
at androidx.compose.ui.node.ModifiedLayoutNode.measure-BRTryo0(ModifiedLayoutNode.kt:37)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:95)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:94)
at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:121)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:75)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_release(OwnerSnapshotObserver.kt:63)
at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:94)
at androidx.compose.ui.node.OuterMeasurablePlaceable.measure-BRTryo0(OuterMeasurablePlaceable.kt:68)
at androidx.compose.ui.node.LayoutNode.measure-BRTryo0(LayoutNode.kt:1172)
at androidx.compose.foundation.layout.BoxKt$boxMeasurePolicy$1.measure-3p2s80s(Box.kt:111)
at androidx.compose.ui.node.InnerPlaceable.measure-BRTryo0(InnerPlaceable.kt:45)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:95)
at androidx.compose.ui.node.OuterMeasurablePlaceable$remeasure$2.invoke(OuterMeasurablePlaceable.kt:94)
at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:1787)
at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:116)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:75)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_release(OwnerSnapshotObserver.kt:63)
at androidx.compose.ui.node.OuterMeasurablePlaceable.remeasure-BRTryo0(OuterMeasurablePlaceable.kt:94)
at androidx.compose.ui.node.LayoutNode.remeasure-BRTryo0$ui_release(LayoutNode.kt:1179)
at androidx.compose.ui.node.LayoutNode.remeasure-BRTryo0$ui_release$default(LayoutNode.kt:1177)
at androidx.compose.ui.node.MeasureAndLayoutDelegate.doRemeasure-0kLqBqw(MeasureAndLayoutDelegate.kt:172)
E/AndroidRuntime: at androidx.compose.ui.node.MeasureAndLayoutDelegate.access$doRemeasure-0kLqBqw(MeasureAndLayoutDelegate.kt:39)
at androidx.compose.ui.node.MeasureAndLayoutDelegate.measureAndLayout(MeasureAndLayoutDelegate.kt:212)
at androidx.compose.ui.platform.AndroidComposeView.measureAndLayout(AndroidComposeView.android.kt:506)
at androidx.compose.ui.platform.AndroidComposeView.dispatchDraw(AndroidComposeView.android.kt:655)
at android.view.View.draw(View.java:21880)
at android.view.View.updateDisplayListIfDirty(View.java:20750)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4542)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4514)
at android.view.View.updateDisplayListIfDirty(View.java:20705)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4542)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4514)
at android.view.View.updateDisplayListIfDirty(View.java:20705)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4542)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4514)
at android.view.View.updateDisplayListIfDirty(View.java:20705)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4542)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4514)
at android.view.View.updateDisplayListIfDirty(View.java:20705)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4542)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4514)
at android.view.View.updateDisplayListIfDirty(View.java:20705)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4542)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4514)
at android.view.View.updateDisplayListIfDirty(View.java:20705)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:725)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:731)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:840)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:4006)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3770)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3079)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1942)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8595)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:988)
at android.view.Choreographer.doCallbacks(Choreographer.java:765)
at android.view.Choreographer.doFrame(Choreographer.java:700)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:967)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7156)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)
In the future one might need to know when the swipe motion is completed and the finger is lifted from the screen (e.g. to open a review screen)
This code has an excessive recomposition for the RatingBar when you type the text
@Composable
private fun Foo() {
Column(modifier = Modifier.padding(20.dp)) {
var rating by remember { mutableFloatStateOf(0f) }
var feedback by remember { mutableStateOf("") }
RatingBar(
value = rating,
painterEmpty = painterResource(id = R.drawable.ic_star_off),
painterFilled = painterResource(id = R.drawable.ic_star_on),
onValueChange = { rating = it },
onRatingChanged = {}
)
TextField(value = feedback, onValueChange = { feedback = it })
}
}
Painter
is unstable param. Check SO for resolve this problem.
When dragging along the RatingBar, if your finger leaves the bounds of the view, the stars stop updating. For example, if I have the RatingBar in the top left corner of the screen, as a user, I would expect that if I touched inside the stars and dragged to the bottom right of the screen, the rating bar should fill up and not lose my touch event when my finger leaves the stars.
I think the rating bar should track the X position of the users finger regardless of where it is on the screen, as long as the touch started inside the RatingBar. This is the same behavior that sliders have in Android, which is why it feels like it should be the default behavior here as well.
Sorry, I am not sure if I just ask a question by creating an issue here.
Are there any ways to change the board thickness of an inactive star?
Hey,
I would love to have customizable star shapes or better vector assets. This would add some more flexibility to the layout and could be part of the RatingBarConfig
.
Hi. Is there any kotlin/compose multiplatform support planned?
Sorry, I am not sure if I just ask a question by creating an issue here.
Are there any ways to change the board thickness of an inactive star?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.