Skip to content

Commit

Permalink
actually scroll to the bottom on longer text messages and silence mor…
Browse files Browse the repository at this point in the history
…e useless linter warnings
  • Loading branch information
zoff99 committed Jan 18, 2025
1 parent 1cf9601 commit 3420942
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ const val AVATAR_SIZE = 40f
const val MAX_AVATAR_SIZE = 70f
val SPACE_AFTER_LAST_MESSAGE = 2.dp
val SPACE_BEFORE_FIRST_MESSAGE = 10.dp
const val LAST_MSG_SCROLL_TO_SCROLL_OFFSET = 10000
const val VIDEO_PLACEHOLDER_ALPHA = 0.2f
val AV_SELECTOR_ICON_SIZE = 10.dp
val VIDEO_IN_BOX_WIDTH_SMALL = 80.dp
Expand Down
11 changes: 6 additions & 5 deletions src/main/kotlin/com/zoffcc/applications/trifa2/GroupMessages.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("FunctionName", "LocalVariableName", "SpellCheckingInspection")
@file:Suppress("FunctionName", "LocalVariableName", "SpellCheckingInspection", "PackageDirectoryMismatch")

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
Expand Down Expand Up @@ -29,7 +29,6 @@ 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 @@ -40,13 +39,15 @@ internal fun GroupMessages(ui_scale: Float, selectedGroupId: String?) {
verticalArrangement = Arrangement.spacedBy(0.dp),
state = listState
) {
item { Spacer(Modifier.size(SPACE_BEFORE_FIRST_MESSAGE)) }
item (key = "FIRST_ITEM") {
Spacer(Modifier.size(SPACE_BEFORE_FIRST_MESSAGE))
}
items(grpmsgs.groupmessages, key = { it.msgDatabaseId }) {
GroupChatMessage(isMyMessage = it.user == myUser, it, ui_scale,
// modifier = Modifier.animateItemPlacement()
)
}
item {
item (key = "LAST_ITEM") {
Box(Modifier.height(SPACE_AFTER_LAST_MESSAGE))
}
}
Expand All @@ -72,7 +73,7 @@ internal fun GroupMessages(ui_scale: Float, selectedGroupId: String?) {
?: -1L
if ((lastVisibleSerial >= prevLastSerial || lastVisibleSerial == -1L) && grpmsgs.groupmessages.lastIndex > 0) {
// scroll to the end if we were at the end
listState.scrollToItem(grpmsgs.groupmessages.lastIndex)
listState.scrollToItem(grpmsgs.groupmessages.lastIndex, LAST_MSG_SCROLL_TO_SCROLL_OFFSET)
// Log.i(com.zoffcc.applications.trifa.TAG, "messages -> scroll to the end")
}
// remember the last serial
Expand Down
11 changes: 6 additions & 5 deletions src/main/kotlin/com/zoffcc/applications/trifa2/Messages.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@file:Suppress("LocalVariableName", "FunctionName", "SpellCheckingInspection")
@file:Suppress("LocalVariableName", "FunctionName", "SpellCheckingInspection", "PackageDirectoryMismatch")

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
Expand Down Expand Up @@ -27,7 +27,6 @@ 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,15 +37,17 @@ internal fun Messages(ui_scale: Float, selectedContactPubkey: String?) {
verticalArrangement = Arrangement.spacedBy(0.dp),
state = listState,
) {
item { Spacer(Modifier.size(SPACE_BEFORE_FIRST_MESSAGE)) }
item (key = "FIRST_ITEM") {
Spacer(Modifier.size(SPACE_BEFORE_FIRST_MESSAGE))
}
// 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,
// modifier = Modifier.animateItemPlacement()
)
}
item {
item (key = "LAST_ITEM") {
Box(Modifier.height(SPACE_AFTER_LAST_MESSAGE))
}
}
Expand All @@ -72,7 +73,7 @@ internal fun Messages(ui_scale: Float, selectedContactPubkey: String?) {
?: -1L
if ((lastVisibleSerial >= prevLastSerial || lastVisibleSerial == -1L) && msgs.messages.lastIndex > 0) {
// scroll to the end if we were at the end
listState.scrollToItem(msgs.messages.lastIndex)
listState.scrollToItem(msgs.messages.lastIndex, LAST_MSG_SCROLL_TO_SCROLL_OFFSET)
// Log.i(com.zoffcc.applications.trifa.TAG, "messages -> scroll to the end")
}
// remember the last serial
Expand Down

0 comments on commit 3420942

Please sign in to comment.