Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@ package com.flipcash.app.messenger.internal.screens.components
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.spring
import androidx.compose.foundation.border
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
Expand All @@ -24,21 +21,19 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.runtime.snapshots.Snapshot
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.paging.compose.LazyPagingItems
import androidx.paging.compose.itemKey
import com.flipcash.app.contacts.ui.ContactAvatar
import com.flipcash.app.messenger.internal.ChatViewModel
import com.flipcash.services.models.chat.MessageContent
import com.flipcash.services.models.chat.MessagePointer
import com.getcode.theme.CodeTheme
import com.getcode.ui.utils.rememberKeyboardController
import com.getcode.ui.utils.sheetResignmentBehavior
import com.getcode.util.toLocalDate
import com.getcode.util.vibration.LocalVibrator
Expand Down Expand Up @@ -106,6 +101,7 @@ internal fun MessageList(
otherReadPointer: MessagePointer? = null,
onAdvanceReadPointer: ((Long) -> Unit)? = null,
) {
val keyboard = rememberKeyboardController()
val listState = rememberLazyListState()
val vibrator = LocalVibrator.current

Expand Down Expand Up @@ -134,7 +130,10 @@ internal fun MessageList(

LazyColumn(
modifier = modifier
.sheetResignmentBehavior(listState),
.sheetResignmentBehavior(listState)
.pointerInput(Unit) {
detectTapGestures { keyboard.hide() }
},
state = listState,
reverseLayout = true,
contentPadding = PaddingValues(
Expand Down Expand Up @@ -230,10 +229,14 @@ internal fun MessageList(
.distinctUntilChanged()
.collectLatest {
// Always scroll for own messages; only near-bottom for incoming
val nearBottom = listState.firstVisibleItemIndex <= 3
val nearBottom = listState.firstVisibleItemIndex <= 5
val newest = messages.peek(0) as? ChatListItem.ContentBubble
if (newest?.isFromSelf == true || nearBottom) {
listState.animateScrollToItem(0)
if (nearBottom) {
listState.animateScrollToItem(0)
} else {
listState.scrollToItem(0)
}
}
}
}
Expand Down
Loading