From c173b343caa3882ea76f01afc78d2f98025dde49 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 7 Oct 2022 10:25:24 -0400 Subject: [PATCH] Fix comment scrolling bug. Fixes #231 --- .../ui/components/comment/CommentNode.kt | 18 ++++--- .../ui/components/comment/CommentNodes.kt | 4 +- .../ui/components/inbox/InboxActivity.kt | 51 ++++++++++--------- .../person/PersonProfileActivity.kt | 1 + 4 files changed, 40 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/com/jerboa/ui/components/comment/CommentNode.kt b/app/src/main/java/com/jerboa/ui/components/comment/CommentNode.kt index 10fe847dc..27c257999 100644 --- a/app/src/main/java/com/jerboa/ui/components/comment/CommentNode.kt +++ b/app/src/main/java/com/jerboa/ui/components/comment/CommentNode.kt @@ -7,6 +7,7 @@ import androidx.compose.animation.shrinkVertically import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyListScope +import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.text.selection.SelectionContainer import androidx.compose.material.AlertDialog import androidx.compose.material.Divider @@ -409,19 +410,20 @@ fun CommentNodesPreview() { val tree = buildCommentsTree(comments, SortType.Hot) CommentNodes( nodes = tree, - moderators = listOf(), - onCommunityClick = {}, + onUpvoteClick = {}, onDownvoteClick = {}, + onReplyClick = {}, + onSaveClick = {}, + onMarkAsReadClick = {}, onEditCommentClick = {}, onDeleteCommentClick = {}, - onMarkAsReadClick = {}, + onReportClick = {}, onPersonClick = {}, + onCommunityClick = {}, + onBlockCreatorClick = {}, onPostClick = {}, - onReportClick = {}, - onReplyClick = {}, - onSaveClick = {}, - onUpvoteClick = {}, - onBlockCreatorClick = {} + moderators = listOf(), + listState = rememberLazyListState() ) } diff --git a/app/src/main/java/com/jerboa/ui/components/comment/CommentNodes.kt b/app/src/main/java/com/jerboa/ui/components/comment/CommentNodes.kt index 253ae06a3..407d28a45 100644 --- a/app/src/main/java/com/jerboa/ui/components/comment/CommentNodes.kt +++ b/app/src/main/java/com/jerboa/ui/components/comment/CommentNodes.kt @@ -2,6 +2,7 @@ package com.jerboa.ui.components.comment import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListScope +import androidx.compose.foundation.lazy.LazyListState import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.remember @@ -12,6 +13,7 @@ import com.jerboa.db.Account @Composable fun CommentNodes( nodes: List, + listState: LazyListState, onUpvoteClick: (commentView: CommentView) -> Unit, onDownvoteClick: (commentView: CommentView) -> Unit, onReplyClick: (commentView: CommentView) -> Unit, @@ -32,7 +34,7 @@ fun CommentNodes( // Holds the un-expanded comment ids val unExpandedComments = remember { mutableStateListOf() } - LazyColumn { + LazyColumn(state = listState) { commentNodeItems( nodes = nodes, isExpanded = { commentId -> !unExpandedComments.contains(commentId) }, diff --git a/app/src/main/java/com/jerboa/ui/components/inbox/InboxActivity.kt b/app/src/main/java/com/jerboa/ui/components/inbox/InboxActivity.kt index 0fdae5543..4cf7392b9 100644 --- a/app/src/main/java/com/jerboa/ui/components/inbox/InboxActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/inbox/InboxActivity.kt @@ -240,6 +240,7 @@ fun InboxTabs( ) { CommentNodes( nodes = nodes, + listState = listState, onUpvoteClick = { commentView -> account?.also { acct -> inboxViewModel.likeComment( @@ -266,22 +267,6 @@ fun InboxTabs( ) navController.navigate("commentReply") }, - onEditCommentClick = { commentView -> - commentEditViewModel.initialize(commentView) - navController.navigate("commentEdit") - }, - onDeleteCommentClick = { commentView -> - account?.also { acct -> - inboxViewModel.deleteComment( - commentView = commentView, - account = acct, - ctx = ctx - ) - } - }, - onReportClick = { commentView -> - navController.navigate("commentReport/${commentView.comment.id}") - }, onSaveClick = { commentView -> account?.also { acct -> inboxViewModel.saveComment( @@ -291,38 +276,54 @@ fun InboxTabs( ) } }, - onBlockCreatorClick = { + onMarkAsReadClick = { commentView -> account?.also { acct -> - inboxViewModel.blockCreator( - creator = it, + inboxViewModel.markReplyAsRead( + commentView = commentView, account = acct, ctx = ctx ) + homeViewModel.updateUnreads(commentView) } }, - onMarkAsReadClick = { commentView -> + onEditCommentClick = { commentView -> + commentEditViewModel.initialize(commentView) + navController.navigate("commentEdit") + }, + onDeleteCommentClick = { commentView -> account?.also { acct -> - inboxViewModel.markReplyAsRead( + inboxViewModel.deleteComment( commentView = commentView, account = acct, ctx = ctx ) - homeViewModel.updateUnreads(commentView) } }, + onReportClick = { commentView -> + navController.navigate("commentReport/${commentView.comment.id}") + }, onPersonClick = { personId -> navController.navigate(route = "profile/$personId") }, onCommunityClick = { community -> navController.navigate(route = "community/${community.id}") }, + onBlockCreatorClick = { + account?.also { acct -> + inboxViewModel.blockCreator( + creator = it, + account = acct, + ctx = ctx + ) + } + }, onPostClick = { postId -> navController.navigate(route = "post/$postId") }, - showPostAndCommunityContext = true, - showRead = true, account = account, - moderators = listOf() + moderators = listOf(), + showPostAndCommunityContext = true, + showRead = true ) } } diff --git a/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt b/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt index c5860ef31..43348ffb8 100644 --- a/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt +++ b/app/src/main/java/com/jerboa/ui/components/person/PersonProfileActivity.kt @@ -412,6 +412,7 @@ fun UserTabs( ) { CommentNodes( nodes = nodes, + listState = listState, onMarkAsReadClick = {}, onUpvoteClick = { commentView -> account?.also { acct ->