Git Product home page Git Product logo

compose-color-picker's Introduction

Android Jetpack Compose Color Picker ๐ŸŽจ

Maven Central

A component that provides two different HSV color pickers, written in Jetpack Compose.

  1. ClassicColorPicker - Square picker with alpha channel
  2. HarmonyColorPicker - Circular wheel with harmony modes (ie complementary, triadic, analogous, shades, monochromatic, tetradic)
color-hsv.mp4
harmony-modes.mp4

How to get started

Add the dependency to your build.gradle file:

implementation 'com.godaddy.android.colorpicker:compose-color-picker:<latest-version>'

// with Android ColorInt extensions
implementation 'com.godaddy.android.colorpicker:compose-color-picker-android:<latest-version>'
// desktop jvm version
implementation 'com.godaddy.android.colorpicker:compose-color-picker-jvm:<latest-version>'

Add ClassicColorPicker to your Compose hierarchy:

import com.godaddy.android.colorpicker.HsvColor

Column {
    ClassicColorPicker(
        onColorChanged = { color: HsvColor ->
            // Do something with the color
        }
    )
}

Or add the HarmonyColorPicker to your Compose hierarchy for an HSV color wheel implementation:

 HarmonyColorPicker(
    harmonyMode = harmonyMode.value,
    modifier = Modifier.size(400.dp),
    onColorChanged = { color ->
        currentColor.value = color
        extraColors.value = color.getColors(colorHarmonyMode = harmonyMode.value)
})

The HarmonyColorPicker allows for you to set a certain ColorHarmonyMode on the wheel. This will then display multiple magnifiers on top of the wheel for the different harmony modes: ie complementary, triadic, analogous, shades, monochromatic, tetradic. If you wish to not display other magnifiers - set ColorHarmonyMode.NONE as your harmonyMode on the wheel.

ClassicColorPicker:

Customizing the control

Size

To change the size of the control, pass in the Modifier option:

import com.godaddy.android.colorpicker.HsvColor

ClassicColorPicker(
    modifier = Modifier.height(200.dp),
    onColorChanged = { color: HsvColor ->
        // Do something with the color
    }
)

Alpha

To hide the alpha bar, change the showAlphaBar parameter:

import com.godaddy.android.colorpicker.HsvColor

ClassicColorPicker(
    showAlphaBar = false,
    onColorChanged = { color: HsvColor ->
        // Do something with the color
    }
)

HarmonyColorPicker

Customizing the control

Harmony Mode

To change the harmony mode of the picker, pass in a different mode into the function:

HarmonyColorPicker(
    harmonyMode = ColorHarmonyMode.SHADES,
    modifier = Modifier.size(400.dp),
    onColorChanged = { color ->
               // do stuff with new color
})

Size

To change the size of the control, pass in the Modifier option:

import com.godaddy.android.colorpicker.HsvColor

HarmonyColorPicker(
    modifier = Modifier.height(200.dp),
    onColorChanged = { color: HsvColor ->
        // Do something with the color
    }
)

Library Contribution Information

Code Formatting

This project uses spotless to enforce code formatting. Run ./gradlew spotlessApply to run formatting before committing.

Releases

  1. Update the version number in color-picker/build.gradle.kts
  2. Make a PR into main and get that merged
  3. Run "Deploy to Sonatype" GitHub Action.
  4. Login to Sonatype and "Close" release. After a few minutes, click "Release".
  5. Release should then be available for download on maven (might take like 30 min to propagate).

compose-color-picker's People

Contributors

agerard-godaddy avatar ffgiraldez avatar huixingwong avatar jawnnypoo avatar jogahcr avatar renovate[bot] avatar riggaroo avatar sproctor avatar thadcodes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

compose-color-picker's Issues

Functionality to desaturate a given color

Hello, is there a function/utility where you can automatically set a selected Color darkened or lightened?, or maybe an option to de-saturate a picked color?

say,
onColorChanged = { hsvColor: HsvColor ->
hsvColor.darken().toColor()
hsvColor.lighten().toColor()
}

Is this project being maintained?

Is this project still being maintained? There are plenty of good improvements in the pull requests sections and the maintainers don't seem to be aware of it. This project is very useful and it's the best ColorPicker library so far. It would be sad if it was forgotten by the maintainers.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • Update dependency com.android.tools.build:gradle to v8

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/android.yml
  • actions/checkout v3
  • actions/setup-java v3
.github/workflows/release.yml
  • actions/checkout v3
  • actions/setup-java v3
gradle
gradle.properties
settings.gradle.kts
build.gradle.kts
  • org.jetbrains.kotlin:kotlin-gradle-plugin 1.7.20
  • com.android.tools.build:gradle 7.3.1
  • com.diffplug.spotless 6.10.0
app/build.gradle.kts
  • org.jetbrains.compose 1.3.0
  • androidx.activity:activity-compose 1.6.1
  • com.google.android.material:material 1.7.0
  • androidx.navigation:navigation-runtime-ktx 2.5.3
  • androidx.navigation:navigation-compose 2.5.3
color-picker/gradle.properties
color-picker/build.gradle.kts
  • org.jetbrains.dokka 1.7.20
  • org.jetbrains.compose 1.3.0
  • com.github.ajalt.colormath:colormath 3.2.0
  • junit:junit 4.13.2
desktop/build.gradle.kts
  • org.jetbrains.compose 1.3.0
gradle/spotless.gradle
jsApp/build.gradle.kts
  • org.jetbrains.compose 1.3.0
gradle-wrapper
gradle/wrapper/gradle-wrapper.properties
  • gradle 7.5.1

  • Check this box to trigger a request for Renovate to run again on this repository

Add compose-ios

Hello everyone.
What do you think about adding compose-ios ??

Best regards.

Animation of movement of coloured circles is stuttering on desktop

Some details:
OS: Linux
Version: 0.4.2
Kotlin: 1.5.31
Jetpack Compose Desktop: 1.0.0

The issue is that the location of the coloured circles will only update sporadically (always updating to the correct position on release of the mouse button).

Interestingly, the colour contained within the circles continues to update as you move the cursor around the colour circle.

My usage is as follows:

HarmonyColorPicker(
harmonyMode = harmonyMode.value,
modifier = Modifier.size(400.dp),
onColorChanged = { hsvColor ->
   currentColor = hsvColor.toColor()
   extraColours.clear()
   extraColors.addAll(hsvColor.getColors(colorHarmonyMode = harmonyMode.value))
})

The library is incredible! Happy to test further or provide a video demo.

Please remove the 22 mb gif ๐Ÿ˜ญ

Github cloning doesn't have much bandwidth. Cloning this repo with a 22mb gif took me 4-5 minutes. Can we move the gif somewhere else with a link or just convert it to mp4?

API 29 and Lower doesn't support BlendMode.Multiply

Looks like BlendMode.Multiply isn't supported on lower API levels with Compose, meaning the underlying Black color isn't displayed.

It is fixed in #4, but we might want to pull in the line change to BlendMode.Modulate to fix it for this instance.

Use within Dialog

Hey folks,

I have tried using this within both Dialog and AlertDialog, and it looks like as soon as the screen is touched in any way, the dialog gets dismissed. I have tried setting dismissOnClickOutside = false in the DialogProperties but this did not solve the issue either. Do you guys have a sample of how to get this to work within the context of a dialog?

Crash on DragGestureDetectorKt

Mostly seems to be happening to Android 11 and Android 9 samsung devices.

Fatal Exception: java.lang.NullPointerException
       at androidx.compose.foundation.gestures.DragGestureDetectorKt.awaitDragOrCancellation-rnUCldI(DragGestureDetectorKt.java:844)
       at androidx.compose.foundation.gestures.DragGestureDetectorKt$awaitDragOrCancellation$1.invokeSuspend(DragGestureDetectorKt.java:12)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:33)
       at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTaskKt.java:178)
       at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTaskKt.java:166)
       at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.java:397)
       at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.java:431)
       at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default(CancellableContinuationImpl.java:420)
       at kotlinx.coroutines.CancellableContinuationImpl.resumeWith(CancellableContinuationImpl.java:328)
       at androidx.compose.ui.input.pointer.SuspendingPointerInputFilter$PointerEventHandlerCoroutine.offerPointerEvent(SuspendingPointerInputFilter.java:511)
       at androidx.compose.ui.input.pointer.SuspendingPointerInputFilter.dispatchPointerEvent(SuspendingPointerInputFilter.java:407)
       at androidx.compose.ui.input.pointer.SuspendingPointerInputFilter.onPointerEvent-H0pRuoY(SuspendingPointerInputFilter.java:420)
       at androidx.compose.ui.input.pointer.Node.dispatchMainEventPass(Node.java:284)
       at androidx.compose.ui.input.pointer.NodeParent.dispatchMainEventPass(NodeParent.java:151)
       at androidx.compose.ui.input.pointer.HitPathTracker.dispatchChanges(HitPathTracker.java:88)
       at androidx.compose.ui.input.pointer.PointerInputEventProcessor.process-BIzXfog(PointerInputEventProcessor.java:80)
       at androidx.compose.ui.platform.AndroidComposeView.handleMotionEvent-8iAsVTc(AndroidComposeView.java:961)
       at androidx.compose.ui.platform.AndroidComposeView.dispatchHoverEvent(AndroidComposeView.java:1123)
       at android.view.View.dispatchGenericMotionEvent(View.java:15309)
       at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2640)
       at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:2222)
       at android.view.View.dispatchGenericMotionEvent(View.java:15309)
       at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2640)
       at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:2222)
       at android.view.View.dispatchGenericMotionEvent(View.java:15309)
       at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2640)
       at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:2222)
       at android.view.View.dispatchGenericMotionEvent(View.java:15309)
       at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2640)
       at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:2222)
       at android.view.View.dispatchGenericMotionEvent(View.java:15309)
       at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2640)
       at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:2222)
       at android.view.View.dispatchGenericMotionEvent(View.java:15309)
       at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2640)
       at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:2222)
       at android.view.View.dispatchGenericMotionEvent(View.java:15309)
       at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2640)
       at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:2222)
       at android.view.View.dispatchGenericMotionEvent(View.java:15309)
       at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2640)
       at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:2222)
       at android.view.View.dispatchGenericMotionEvent(View.java:15309)
       at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2640)
       at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:2222)
       at android.view.View.dispatchGenericMotionEvent(View.java:15309)
       at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:2640)
       at android.view.ViewGroup.dispatchHoverEvent(ViewGroup.java:2222)
       at com.android.internal.policy.DecorView.dispatchHoverEvent(DecorView.java:4195)
       at android.view.View.dispatchGenericMotionEvent(View.java:15309)
       at com.android.internal.policy.DecorView.superDispatchGenericMotionEvent(DecorView.java:921)
       at com.android.internal.policy.PhoneWindow.superDispatchGenericMotionEvent(PhoneWindow.java:1967)
       at android.app.Activity.dispatchGenericMotionEvent(Activity.java:4218)
       at androidx.appcompat.view.WindowCallbackWrapper.dispatchGenericMotionEvent(WindowCallbackWrapper.java:79)
       at com.android.internal.policy.DecorView.dispatchGenericMotionEvent(DecorView.java:885)
       at android.view.View.dispatchPointerEvent(View.java:15460)
       at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:7457)
       at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:7233)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:6595)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:6652)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:6618)
       at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:6786)
       at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:6626)
       at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:6843)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:6599)
       at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:6652)
       at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:6618)
       at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:6626)
       at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:6599)
       at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:9880)
       at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:9718)
       at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:9671)
       at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:10014)
       at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:220)
       at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
       at android.os.MessageQueue.next(MessageQueue.java:335)
       at android.os.Looper.loop(Looper.java:206)
       at android.app.ActivityThread.main(ActivityThread.java:8595)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

Support Jetpack Compose Web & Material3

To Support Jetpack Compose Web, This pull request could be merged
#58

Material Libraries Should Be Changed To Material3 Libraries , Because material3 is better
Project should also use Kotlin 1.8.0 and Jetbrains Compose Version 1.3.0

Modifier.background doesn't reflect color changes when Color.Transparent is specified as initial color picker parameter

Hello, considering the code below, I have a use-case where I have to specify a Color.Transparent as the initial settings of the color picker, however it doesn't reflect the changes when I'm moving around the color picker. I have 3 commented codes inside onColorChanged where only one of them works in this use-case, I'm not sure if my use-case doesn't make sense and this is an intended behavior of the Color picker but any feedback would be greatly appreciated. Thank you in advance.

var color by remember { mutableStateOf(Color.Transparent) } 
Log.e("ColorChanged", "$color")
Column(
    modifier = Modifier.fillMaxSize()
 ) {
    Box (
        modifier = Modifier
            .size(100.dp)
            .background(color)
    )
       
  
    ClassicColorPicker(
        showAlphaBar = false,
        color = Color.Transparent,  // also works when supplied with another color (e.g Color.Black)
        modifier = Modifier
            .height(280.dp)
            .padding(vertical = 16.dp),
        onColorChanged = { hsvColor: HsvColor ->
            // color = hsvColor.toColor() // doesn't work
            // color = hsvColor.copy(alpha = hsvColor.alpha).toColor() // doesn't work
            color = hsvColor.copy(alpha = 1f).toColor() // workaround
        }
    )
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.