Skip to content

Instantly share code, notes, and snippets.

@linreal
Last active January 6, 2026 13:19
Show Gist options
  • Select an option

  • Save linreal/16b9772ad8c42d1c893f92f096803688 to your computer and use it in GitHub Desktop.

Select an option

Save linreal/16b9772ad8c42d1c893f92f096803688 to your computer and use it in GitHub Desktop.
// RecyclerView
override fun getItemViewType(position: Int): Int {
return when (items[position]) {
is TextMessage -> VIEW_TYPE_TEXT
is ImageMessage -> VIEW_TYPE_IMAGE
is VideoMessage -> VIEW_TYPE_VIDEO
else -> VIEW_TYPE_UNKNOWN
}
}
// LazyColumn
LazyColumn {
items(
items = messages,
key = { message -> message.id },
contentType = { message ->
when (message) {
is Message.TextMessage -> "text"
is Message.ImageMessage -> "image"
is Message.VideoMessage -> "video"
}
}
) { message ->
MessageItem(message)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment