Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dombroks
Copy link

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.

Comment on lines +64 to +72
private fun generateRandomColor(): Color {
return Color(
red = (0..255).random() / 255f,
green = (0..255).random() / 255f,
blue = (0..255).random() / 255f,
alpha = 1f
)
}

Copy link
Owner

@qamarelsafadi qamarelsafadi Nov 17, 2024

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)]
}

Copy link
Author

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?

Copy link
Owner

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.

@qamarelsafadi
Copy link
Owner

Well done @dombroks ! could you please provide a recording how it will look like with your current implementation?

@dombroks
Copy link
Author

Absolutely, @qamarelsafadi

Screenrecorder-2024-11-17-19-22-11-456.mp4

@qamarelsafadi
Copy link
Owner

@dombroks take a pull from master to merge this PR :D !

@dombroks
Copy link
Author

You've added changes! Okay, It will be ready to be merged tomorrow.

@dombroks
Copy link
Author

@qamarelsafadi does the app runs for you?

I got issues after pulling the latest changes, regarding two dependencies:

  1. Dependency 'androidx.core:core-ktx:1.15.0' requires libraries and applications that
    depend on it to compile against version 35 or later of the
    Android APIs.

  2. Dependency 'androidx.core:core:1.15.0' requires libraries and applications that
    depend on it to compile against version 35 or later of the
    Android APIs.

You've decreased the compileSdk version from 35 to 34 yesterday, did that work for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: adding a unique color for each composable.
2 participants