Skip to content

Commit

Permalink
animate lazylist item changes (which seems it does not do anything on…
Browse files Browse the repository at this point in the history
… desktop)
  • Loading branch information
zoff99 committed Mar 25, 2024
1 parent 5f8f23b commit b8706dd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main/kotlin/com/zoffcc/applications/trifa2/ChatMessage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ fun randomColor() = Color(

@OptIn(ExperimentalFoundationApi::class)
@Composable
inline fun ChatMessage(isMyMessage: Boolean, message: UIMessage, ui_scale: Float) {
inline fun ChatMessage(isMyMessage: Boolean, message: UIMessage, ui_scale: Float, modifier: Modifier = Modifier) {
val TAG = "trifa.ChatMessage"
Box(
modifier = Modifier.fillMaxWidth(),
modifier = modifier.fillMaxWidth(),
contentAlignment = if (isMyMessage) Alignment.CenterEnd else Alignment.CenterStart,
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ fun GroupTriangle(risingToTheRight: Boolean, background: Color, padding_bottom:

@OptIn(ExperimentalFoundationApi::class, DelicateCoroutinesApi::class)
@Composable
inline fun GroupChatMessage(isMyMessage: Boolean, groupmessage: UIGroupMessage, ui_scale: Float) {
inline fun GroupChatMessage(isMyMessage: Boolean, groupmessage: UIGroupMessage, ui_scale: Float, modifier: Modifier = Modifier) {
Box(
modifier = Modifier.fillMaxWidth(),
modifier = modifier.fillMaxWidth(),
contentAlignment = if (isMyMessage) Alignment.CenterEnd else Alignment.CenterStart
) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.VerticalScrollbar
import androidx.compose.foundation.layout.*
Expand Down Expand Up @@ -26,6 +27,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import org.jetbrains.compose.resources.ExperimentalResourceApi

@OptIn(ExperimentalFoundationApi::class)
@Composable
internal fun GroupMessages(ui_scale: Float, selectedGroupId: String?) {
val listState = rememberLazyListState()
Expand All @@ -38,7 +40,8 @@ internal fun GroupMessages(ui_scale: Float, selectedGroupId: String?) {
) {
item { Spacer(Modifier.size(SPACE_BEFORE_FIRST_MESSAGE)) }
items(grpmsgs.groupmessages, key = { it.msgDatabaseId }) {
GroupChatMessage(isMyMessage = it.user == myUser, it, ui_scale)
GroupChatMessage(isMyMessage = it.user == myUser, it, ui_scale,
modifier = Modifier.animateItemPlacement())
}
item {
Box(Modifier.height(SPACE_AFTER_LAST_MESSAGE))
Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/com/zoffcc/applications/trifa2/Messages.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.VerticalScrollbar
import androidx.compose.foundation.layout.*
Expand All @@ -24,6 +25,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import org.jetbrains.compose.resources.ExperimentalResourceApi

@OptIn(ExperimentalFoundationApi::class)
@Composable
internal fun Messages(ui_scale: Float, selectedContactPubkey: String?) {
val listState = rememberLazyListState()
Expand All @@ -38,7 +40,8 @@ internal fun Messages(ui_scale: Float, selectedContactPubkey: String?) {
// Log.i(com.zoffcc.applications.trifa.TAG, "LazyColumn --> draw")
items(msgs.messages, key = { it.msgDatabaseId }) {
// Log.i(com.zoffcc.applications.trifa.TAG, "LazyColumn -> it.msgDatabaseId = " + it.msgDatabaseId)
ChatMessage(isMyMessage = (it.user == myUser), it, ui_scale)
ChatMessage(isMyMessage = (it.user == myUser), it, ui_scale,
modifier = Modifier.animateItemPlacement())
}
item {
Box(Modifier.height(SPACE_AFTER_LAST_MESSAGE))
Expand Down

0 comments on commit b8706dd

Please sign in to comment.