@@ -15,10 +15,10 @@ import androidx.compose.foundation.layout.padding
15
15
import androidx.compose.foundation.layout.wrapContentSize
16
16
import androidx.compose.runtime.Composable
17
17
import androidx.compose.runtime.State
18
- import androidx.compose.runtime.derivedStateOf
19
18
import androidx.compose.runtime.getValue
20
19
import androidx.compose.runtime.mutableStateOf
21
20
import androidx.compose.runtime.remember
21
+ import androidx.compose.runtime.rememberUpdatedState
22
22
import androidx.compose.runtime.setValue
23
23
import androidx.compose.ui.Modifier
24
24
import androidx.compose.ui.geometry.Offset
@@ -48,6 +48,7 @@ fun HarmonyColorPicker(
48
48
.fillMaxWidth()
49
49
) {
50
50
val hsvColor = remember { mutableStateOf(HsvColor .from(color)) }
51
+ val updatedOnColorChanged by rememberUpdatedState(onColorChanged)
51
52
52
53
HarmonyColorPickerWithMagnifiers (
53
54
modifier = Modifier
@@ -56,7 +57,7 @@ fun HarmonyColorPicker(
56
57
hsvColor = hsvColor,
57
58
onColorChanged = {
58
59
hsvColor.value = it
59
- onColorChanged (it)
60
+ updatedOnColorChanged (it)
60
61
},
61
62
harmonyMode = harmonyMode
62
63
)
@@ -68,7 +69,7 @@ fun HarmonyColorPicker(
68
69
.weight(0.2f ),
69
70
onValueChange = { value ->
70
71
hsvColor.value = hsvColor.value.copy(value = value)
71
- onColorChanged (hsvColor.value)
72
+ updatedOnColorChanged (hsvColor.value)
72
73
},
73
74
currentColor = hsvColor.value
74
75
)
@@ -90,14 +91,11 @@ private fun HarmonyColorPickerWithMagnifiers(
90
91
.aspectRatio(1f , matchHeightConstraintsFirst = true )
91
92
92
93
) {
94
+ val updatedOnColorChanged by rememberUpdatedState(onColorChanged)
93
95
val diameterPx = remember(constraints.maxWidth) {
94
96
mutableStateOf(constraints.maxWidth)
95
97
}
96
- val magnifierSize = remember {
97
- derivedStateOf {
98
- IntSize (diameterPx.value, diameterPx.value)
99
- }
100
- }
98
+
101
99
var animateChanges by remember {
102
100
mutableStateOf(false )
103
101
}
@@ -108,10 +106,10 @@ private fun HarmonyColorPickerWithMagnifiers(
108
106
fun updateColorWheel (newPosition : Offset , animate : Boolean ) {
109
107
// Work out if the new position is inside the circle we are drawing, and has a
110
108
// valid color associated to it. If not, keep the current position
111
- val newColor = colorForPosition(newPosition, magnifierSize .value, hsvColor.value.value)
109
+ val newColor = colorForPosition(newPosition, IntSize (diameterPx .value, diameterPx.value) , hsvColor.value.value)
112
110
if (newColor != null ) {
113
111
animateChanges = animate
114
- onColorChanged (newColor)
112
+ updatedOnColorChanged (newColor)
115
113
}
116
114
}
117
115
0 commit comments