From 73e0f799afaea05ddc470989329264c7f6d750c4 Mon Sep 17 00:00:00 2001 From: Simon Derr Date: Wed, 8 May 2024 23:04:19 +0200 Subject: [PATCH] quickfix for occasional color reset to white on recomposition On rare occasions, (was seen using a color picker in an animated widget) the color picker will reset the selected color to white after a recomposition. This seems to be due to onSizeChanged() being called, even though the color picker did not really change size. For the HSV color picker it is possible to re-select automatically the previously picked color, since the coordinates can be calculated. For the ImageColorPicker, a more elaborate fix would be needed. --- .../skydoves/colorpicker/compose/ColorPickerController.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/colorpicker-compose/src/main/kotlin/com/github/skydoves/colorpicker/compose/ColorPickerController.kt b/colorpicker-compose/src/main/kotlin/com/github/skydoves/colorpicker/compose/ColorPickerController.kt index 1373b58..2c6e2f7 100644 --- a/colorpicker-compose/src/main/kotlin/com/github/skydoves/colorpicker/compose/ColorPickerController.kt +++ b/colorpicker-compose/src/main/kotlin/com/github/skydoves/colorpicker/compose/ColorPickerController.kt @@ -134,7 +134,11 @@ public class ColorPickerController { } paletteBitmap = resized.asImageBitmap() copiedBitmap.recycle() - selectCenter(fromUser = false) + if (isHsvColorPalette) { + selectByColor(_selectedColor.value, false) + } else { + selectCenter(fromUser = false) + } reviseTick.intValue++ }