Skip to content

Commit

Permalink
Fix comment scrolling bug. Fixes #231
Browse files Browse the repository at this point in the history
  • Loading branch information
dessalines committed Oct 7, 2022
1 parent 980b1e9 commit c173b34
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 34 deletions.
18 changes: 10 additions & 8 deletions app/src/main/java/com/jerboa/ui/components/comment/CommentNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -12,6 +13,7 @@ import com.jerboa.db.Account
@Composable
fun CommentNodes(
nodes: List<CommentNodeData>,
listState: LazyListState,
onUpvoteClick: (commentView: CommentView) -> Unit,
onDownvoteClick: (commentView: CommentView) -> Unit,
onReplyClick: (commentView: CommentView) -> Unit,
Expand All @@ -32,7 +34,7 @@ fun CommentNodes(
// Holds the un-expanded comment ids
val unExpandedComments = remember { mutableStateListOf<Int>() }

LazyColumn {
LazyColumn(state = listState) {
commentNodeItems(
nodes = nodes,
isExpanded = { commentId -> !unExpandedComments.contains(commentId) },
Expand Down
51 changes: 26 additions & 25 deletions app/src/main/java/com/jerboa/ui/components/inbox/InboxActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ fun InboxTabs(
) {
CommentNodes(
nodes = nodes,
listState = listState,
onUpvoteClick = { commentView ->
account?.also { acct ->
inboxViewModel.likeComment(
Expand All @@ -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(
Expand All @@ -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
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ fun UserTabs(
) {
CommentNodes(
nodes = nodes,
listState = listState,
onMarkAsReadClick = {},
onUpvoteClick = { commentView ->
account?.also { acct ->
Expand Down

0 comments on commit c173b34

Please sign in to comment.