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

Make brightness bar optional #44

Merged
merged 4 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.godaddy.android.colorpicker

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.material.DropdownMenu
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.Switch
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.material.TopAppBar
Expand Down Expand Up @@ -47,6 +49,9 @@ fun HarmonyColorPickerScreen(navController: NavController) {
var harmonyMode by remember {
mutableStateOf(ColorHarmonyMode.ANALOGOUS)
}
var showBrightnessBar by remember {
mutableStateOf(true)
}
TextButton(onClick = {
expanded = true
}) {
Expand All @@ -67,12 +72,22 @@ fun HarmonyColorPickerScreen(navController: NavController) {
HarmonyColorPicker(
modifier = Modifier.size(400.dp),
harmonyMode = harmonyMode,
color = currentColor
color = currentColor,
fixedBrightness = 1f.takeIf { !showBrightnessBar }
) { color ->
currentColor = color
extraColors = color.getColors(colorHarmonyMode = harmonyMode)
}
ColorPaletteBar(modifier = Modifier.fillMaxWidth().height(70.dp), colors = extraColors)
Row {
Text("Show Brightness Bar")
Switch(
checked = showBrightnessBar,
onCheckedChange = { checked ->
showBrightnessBar = checked
}
)
}
TextButton(onClick = { currentColor = HsvColor.from(Color.Green) }) {
Text("Reset To Green")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,17 @@ fun HarmonyColorPicker(
)
}

/**
*
* Will show a brightness bar if [fixedBrightness] is null
* otherwise all colors are given the provided brightness value
*/
@Composable
fun HarmonyColorPicker(
modifier: Modifier = Modifier,
harmonyMode: ColorHarmonyMode,
color: HsvColor,
fixedBrightness: Float? = null,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, to keep consistency with ClassicColorPicker, please rename it to showBrightnessBar.

if a user wants a specific brightness, it should set showBrightnessBar to false and set the brightness in the provided color.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ffgiraldez thanks for pointing that out. I didn't notice ClassicColorPicker had that. Updated now

onColorChanged: (HsvColor) -> Unit
) {
BoxWithConstraints(modifier) {
Expand All @@ -87,7 +93,14 @@ fun HarmonyColorPicker(
.fillMaxHeight()
.fillMaxWidth()
) {
val updatedColor by rememberUpdatedState(color)
val adjustedColor = color.run {
if (fixedBrightness != null) {
copy(value = fixedBrightness)
} else {
this
}
}
val updatedColor by rememberUpdatedState(adjustedColor)
val updatedOnValueChanged by rememberUpdatedState(onColorChanged)

HarmonyColorPickerWithMagnifiers(
Expand All @@ -101,16 +114,18 @@ fun HarmonyColorPicker(
harmonyMode = harmonyMode
)

BrightnessBar(
modifier = Modifier
.padding(top = 16.dp)
.fillMaxWidth()
.weight(0.2f),
onValueChange = { value ->
updatedOnValueChanged(updatedColor.copy(value = value))
},
currentColor = updatedColor
)
if (fixedBrightness == null) {
BrightnessBar(
modifier = Modifier
.padding(top = 16.dp)
.fillMaxWidth()
.weight(0.2f),
onValueChange = { value ->
updatedOnValueChanged(updatedColor.copy(value = value))
},
currentColor = updatedColor
)
}
}
}
}
Expand Down