-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enhance: Add a unique color for each composable border and recomposition count text #2
base: master
Are you sure you want to change the base?
Conversation
private fun generateRandomColor(): Color { | ||
return Color( | ||
red = (0..255).random() / 255f, | ||
green = (0..255).random() / 255f, | ||
blue = (0..255).random() / 255f, | ||
alpha = 1f | ||
) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about using this instead of doing those calculations?
@Composable
fun getRandomThemeColor(): Color {
val colors = MaterialTheme.colors
val colorList = listOf(
colors.primary,
colors.primaryVariant,
colors.secondary,
colors.secondaryVariant,
colors.background,
colors.surface,
colors.error
)
return colorList[Random.nextInt(colorList.size)]
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first implementation generates a random color while the one you suggested returns a random color from a predefined list of theme colors. Is there a reason for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have concerns that generating those random colors will add an overhead for anyone is using it. But let's proceed we can have benchmark for it later.
Well done @dombroks ! could you please provide a recording how it will look like with your current implementation? |
Absolutely, @qamarelsafadi Screenrecorder-2024-11-17-19-22-11-456.mp4 |
@dombroks take a pull from master to merge this PR :D ! |
You've added changes! Okay, It will be ready to be merged tomorrow. |
@qamarelsafadi does the app runs for you? I got issues after pulling the latest changes, regarding two dependencies:
You've decreased the compileSdk version from 35 to 34 yesterday, did that work for you? |
Summary
This PR enhances the UI by automatically assigning a unique color to each composable element border based on unique Id. This allows for easily identifying different composables in the UI for better debugging and visual differentiation.
Issue
Closes #1 .
Motivation
In large or complex UIs, it can be difficult to visually differentiate between composables for debugging purposes. This enhancement assigns a unique color to each composable border and recomposition count text, allowing developers to track recompositions and identify elements more easily during UI development.
Changes made
Introduced a colors map where each composable border gets a unique color based on a unique Id.
The color is generated randomly for each composable on the first recomposition, ensuring that it remains consistent across recompositions.
Considerations
An assigned color for a composable border might be the same as the background color which make it invisible.
Color randomness implementation might result in visually indistinct or overly similar colors.