https://kotlinlang.org logo
#compose-desktop
Title
# compose-desktop
z

Zoff

02/27/2024, 3:13 PM
can i have access in a lazycolumn to the previous element? i have a chat app, and now if the same person sends multiple messages i want the chat bubbles to be closer together and not every single bubble needs to include the name. since its the same person. i can do this on android. how do i do something like that on compose desktop in a lazycolumn?
k

Kirill Grouchnikov

02/27/2024, 3:52 PM
“I can do this on Android” -> presumably by looking at the contact info and timestamps? What is the Android-specific code that can’t be ported to the desktop part of your codebase?
r

rob42

02/27/2024, 9:47 PM
I'd consider doing this when populating the "item { }"s. e.g.
Copy code
messages.forEachIndex { idx, msg ->
  val prevMsg = messages[idx]
  item {
    ChatBubble(
       name = if (prevMsg.sender == msg.sender) "" else msg.sender,
       text = msg.text,
    )
  }
}
There's nothing special about LazyColumn here, the approach would be the same if this was a regular old column.
z

Zoff

02/28/2024, 8:54 AM
thanks i will try that