Skip to content

Commit 9eb7172

Browse files
committed
Auto-scroll to top when new live chat messages arrive
1 parent eb1f1fa commit 9eb7172

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentInfo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CommentInfo(
1313
val nextPage: Page?,
1414
val commentCount: Int,
1515
val isCommentsDisabled: Boolean,
16-
val isLiveChat: Boolean = false
16+
val isLiveChat: Boolean
1717
) {
1818
constructor(commentsInfo: CommentsInfo) : this(
1919
commentsInfo.serviceId,

app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentSection.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import androidx.compose.material3.MaterialTheme
1212
import androidx.compose.material3.Surface
1313
import androidx.compose.material3.Text
1414
import androidx.compose.runtime.Composable
15+
import androidx.compose.runtime.LaunchedEffect
1516
import androidx.compose.runtime.getValue
1617
import androidx.compose.ui.Alignment
1718
import androidx.compose.ui.Modifier
@@ -59,6 +60,14 @@ private fun CommentSection(
5960
val nestedScrollInterop = rememberNestedScrollInteropConnection()
6061
val state = rememberLazyListState()
6162

63+
// Auto-scroll to top when new live chat messages arrive
64+
val isLiveChat = uiState is Resource.Success && uiState.data.isLiveChat
65+
LaunchedEffect(liveChatItems.size) {
66+
if (isLiveChat && liveChatItems.isNotEmpty()) {
67+
state.scrollToItem(0)
68+
}
69+
}
70+
6271
LazyColumnThemedScrollbar(state = state) {
6372
LazyColumn(
6473
modifier = Modifier

app/src/main/java/org/schabi/newpipe/viewmodels/CommentsViewModel.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import kotlinx.coroutines.flow.SharingStarted
1717
import kotlinx.coroutines.flow.StateFlow
1818
import kotlinx.coroutines.flow.filterIsInstance
1919
import kotlinx.coroutines.flow.flatMapLatest
20-
import kotlinx.coroutines.flow.flowOf
2120
import kotlinx.coroutines.flow.flowOn
2221
import kotlinx.coroutines.flow.map
2322
import kotlinx.coroutines.flow.stateIn

0 commit comments

Comments
 (0)