Paul Woitaschek
05/22/2021, 7:33 PMEmojiCompat.get()
and that breaks the preview because EmojiCompat wasnt initialized because as we're inside the preview the application wasn't created.
(sth like View.isInEditMode
but statically available?)Adam Powell
05/22/2021, 7:41 PMPaul Woitaschek
05/22/2021, 7:42 PMPaul Woitaschek
05/22/2021, 7:42 PMEmojiDrawable
classPaul Woitaschek
05/23/2021, 3:07 PMMark Murphy
05/23/2021, 4:25 PMEmojiDrawable
directly?
If so, could you change it such that it receives the drawable (or supplier of drawables) as a parameter? Then, if you set up a default value of the parameter that does not use EmojiDrawable
itself, the preview should be isolated from EmojiDrawable
and should not need EmojiCompat
.
Or, as Adam suggests, perhaps your supplier of drawables could be provided by a CompositionLocal
, with a default implementation that does not depend upon EmojiCompat
. The preview would use that default implementation, and higher-level composables would provide the EmojiDrawable
-based implementation.
On the whole, the advice seems to be: if you are encountering preview problems because of platform considerations, your composable is insufficiently isolated from the platform.Paul Woitaschek
05/23/2021, 4:26 PMPaul Woitaschek
05/23/2021, 7:25 PMLocalInspectionMode
🙂Paul Woitaschek
05/23/2021, 7:33 PM@Composable
internal fun rememberEmojiPainter(emoji: Emoji): Painter {
val useEmojiCompat = !LocalInspectionMode.current
return remember(emoji) {
val drawable = EmojiDrawable(emoji, useEmojiCompat = useEmojiCompat)
DrawablePainter(drawable)
}
}