Skip to content

Commit bb8d441

Browse files
committed
actually scroll to the bottom on longer text messages and silence more useless linter warnings
1 parent ffcd7df commit bb8d441

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/main/kotlin/Main.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ const val AVATAR_SIZE = 40f
251251
const val MAX_AVATAR_SIZE = 70f
252252
val SPACE_AFTER_LAST_MESSAGE = 2.dp
253253
val SPACE_BEFORE_FIRST_MESSAGE = 10.dp
254+
const val LAST_MSG_SCROLL_TO_SCROLL_OFFSET = 10000
254255
const val VIDEO_PLACEHOLDER_ALPHA = 0.2f
255256
val AV_SELECTOR_ICON_SIZE = 10.dp
256257
val VIDEO_IN_BOX_WIDTH_SMALL = 80.dp

src/main/kotlin/com/zoffcc/applications/trifa2/GroupMessages.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@file:Suppress("FunctionName", "LocalVariableName", "SpellCheckingInspection")
1+
@file:Suppress("FunctionName", "LocalVariableName", "SpellCheckingInspection", "PackageDirectoryMismatch")
22

33
import androidx.compose.foundation.ExperimentalFoundationApi
44
import androidx.compose.foundation.Image
@@ -29,7 +29,6 @@ import androidx.compose.ui.res.painterResource
2929
import androidx.compose.ui.unit.dp
3030
import org.jetbrains.compose.resources.ExperimentalResourceApi
3131

32-
@OptIn(ExperimentalFoundationApi::class)
3332
@Composable
3433
internal fun GroupMessages(ui_scale: Float, selectedGroupId: String?) {
3534
val listState = rememberLazyListState()
@@ -40,13 +39,15 @@ internal fun GroupMessages(ui_scale: Float, selectedGroupId: String?) {
4039
verticalArrangement = Arrangement.spacedBy(0.dp),
4140
state = listState
4241
) {
43-
item { Spacer(Modifier.size(SPACE_BEFORE_FIRST_MESSAGE)) }
42+
item (key = "FIRST_ITEM") {
43+
Spacer(Modifier.size(SPACE_BEFORE_FIRST_MESSAGE))
44+
}
4445
items(grpmsgs.groupmessages, key = { it.msgDatabaseId }) {
4546
GroupChatMessage(isMyMessage = it.user == myUser, it, ui_scale,
4647
// modifier = Modifier.animateItemPlacement()
4748
)
4849
}
49-
item {
50+
item (key = "LAST_ITEM") {
5051
Box(Modifier.height(SPACE_AFTER_LAST_MESSAGE))
5152
}
5253
}
@@ -72,7 +73,7 @@ internal fun GroupMessages(ui_scale: Float, selectedGroupId: String?) {
7273
?: -1L
7374
if ((lastVisibleSerial >= prevLastSerial || lastVisibleSerial == -1L) && grpmsgs.groupmessages.lastIndex > 0) {
7475
// scroll to the end if we were at the end
75-
listState.scrollToItem(grpmsgs.groupmessages.lastIndex)
76+
listState.scrollToItem(grpmsgs.groupmessages.lastIndex, LAST_MSG_SCROLL_TO_SCROLL_OFFSET)
7677
// Log.i(com.zoffcc.applications.trifa.TAG, "messages -> scroll to the end")
7778
}
7879
// remember the last serial

src/main/kotlin/com/zoffcc/applications/trifa2/Messages.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@file:Suppress("LocalVariableName", "FunctionName", "SpellCheckingInspection")
1+
@file:Suppress("LocalVariableName", "FunctionName", "SpellCheckingInspection", "PackageDirectoryMismatch")
22

33
import androidx.compose.foundation.ExperimentalFoundationApi
44
import androidx.compose.foundation.Image
@@ -27,7 +27,6 @@ import androidx.compose.ui.res.painterResource
2727
import androidx.compose.ui.unit.dp
2828
import org.jetbrains.compose.resources.ExperimentalResourceApi
2929

30-
@OptIn(ExperimentalFoundationApi::class)
3130
@Composable
3231
internal fun Messages(ui_scale: Float, selectedContactPubkey: String?) {
3332
val listState = rememberLazyListState()
@@ -38,15 +37,17 @@ internal fun Messages(ui_scale: Float, selectedContactPubkey: String?) {
3837
verticalArrangement = Arrangement.spacedBy(0.dp),
3938
state = listState,
4039
) {
41-
item { Spacer(Modifier.size(SPACE_BEFORE_FIRST_MESSAGE)) }
40+
item (key = "FIRST_ITEM") {
41+
Spacer(Modifier.size(SPACE_BEFORE_FIRST_MESSAGE))
42+
}
4243
// Log.i(com.zoffcc.applications.trifa.TAG, "LazyColumn --> draw")
4344
items(msgs.messages, key = { it.msgDatabaseId }) {
4445
// Log.i(com.zoffcc.applications.trifa.TAG, "LazyColumn -> it.msgDatabaseId = " + it.msgDatabaseId)
4546
ChatMessage(isMyMessage = (it.user == myUser), it, ui_scale,
4647
// modifier = Modifier.animateItemPlacement()
4748
)
4849
}
49-
item {
50+
item (key = "LAST_ITEM") {
5051
Box(Modifier.height(SPACE_AFTER_LAST_MESSAGE))
5152
}
5253
}
@@ -72,7 +73,7 @@ internal fun Messages(ui_scale: Float, selectedContactPubkey: String?) {
7273
?: -1L
7374
if ((lastVisibleSerial >= prevLastSerial || lastVisibleSerial == -1L) && msgs.messages.lastIndex > 0) {
7475
// scroll to the end if we were at the end
75-
listState.scrollToItem(msgs.messages.lastIndex)
76+
listState.scrollToItem(msgs.messages.lastIndex, LAST_MSG_SCROLL_TO_SCROLL_OFFSET)
7677
// Log.i(com.zoffcc.applications.trifa.TAG, "messages -> scroll to the end")
7778
}
7879
// remember the last serial

0 commit comments

Comments
 (0)