https://kotlinlang.org logo
Title
o

orangy

01/08/2021, 2:24 PM
Another confusing piece is
imageResource
(composable with remember) vs
imageFromResource
(just creates ImageBitmap). In a composable context it’s easy to use the wrong one and cause excessive bitmap creations. Consider renaming one of them to be not so similar and making it more obvious from the name when to use which.
j

jim

01/08/2021, 2:28 PM
imageResource
should be renamed to
rememberImageResource
to conform to our internal API guidelines; can you file a bug please (https://github.com/JetBrains/compose-jb/issues) and post a link to it here in slack?
o

orangy

01/08/2021, 2:37 PM
j

jim

01/08/2021, 3:01 PM
Hmm, actually, looking at this a bit more, I think maybe the fact it uses remember is intended to be a transparent implementation detail and is used purely for performance reasons, so maybe the
remember
prefix is not correct here.
I wonder if the actual bug is that
imageFromResource
doesn't do any caching, and they should both behave more similarly. Although it seems like we should provide apps with a way to load images from outside of a Composable call tree. Perhaps
cachedImageResource
for the variant that does remember caching? I'll bring it up with API council. Thanks for flagging.
o

orangy

01/08/2021, 4:29 PM
imageFromResource
is not composable, so it can be used for manual caching, e.g. an object with static resources. It looks like the semantic is fine, it’s just that names are confusing
I would may be use
loadImageFromResource
so it highlights it does the job every time
2