Do we have a `colorResource` for decoding color re...
# compose
a
Do we have a
colorResource
for decoding color references?
k
Yeah, there is a
Color(color: Long)
which expects a The 32-bit ARGB color int and a
Color(@ColorInt color: Int)
which needs a resource
a
In as, the res int resolves as a color on the sidebar
Kinda throws you off
j
mmm, I think
@ColorInt
Denotes that the annotated element represents a packed color, right?
k
yes you are right
Copy code
represents a packed color int, {@code AARRGGBB}
j
I don't think anyone has written
colorResource()
yet, but it should be an easy function to write. Hint hint, could be a good first bug if someone is looking to submit a pull request 🙂.
👍 3
k
if this is correct, it is not that hard 😅
Copy code
@CheckResult(suggest = "+")
fun colorResource(@ColorRes resId: Int) = effectOf<Color> {
  val context = +ambient(ContextAmbient)
  val res = context.resources
  +memo(resId) {
    Color(ContextCompat.getColor(context, resId))
  }
}
💯 1