https://kotlinlang.org logo
#compose
Title
# compose
n

Nat Strangerweather

06/15/2022, 8:34 PM
If I convert a
Color
value to
Int
(using
toArgb()
) so I can save it in Datastore, how would I then convert the
Int
back to Jetpack Compose
Color
?
s

Scott Peterson

06/15/2022, 8:35 PM
maybe
Color.valueOf(theIntValue)
?
n

Nat Strangerweather

06/15/2022, 8:39 PM
Thanks but I can't write
Color.valueOf
... The option is not available.
r

romainguy

06/15/2022, 8:39 PM
There’s a
Color(Int)
function for this
You can also
Color(color.toULong() shl 32)
😄
f

Francesc

06/15/2022, 8:40 PM
https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]mmonMain/kotlin/androidx/compose/ui/graphics/Color.kt?q=color @Stable fun *Color*(/*@*Color*Int*/ color: Int): Color { return *Color*(value = color.toULong() shl 32) }
n

Nat Strangerweather

06/15/2022, 8:41 PM
Cool, thank you! 😊
r

romainguy

06/15/2022, 8:51 PM
You could also save it as `ULong`/`Long` since that’s how a
Color
is stored internally
👍 1
525 Views