@@ -11,6 +11,7 @@ import androidx.compose.material3.MaterialTheme
1111import androidx.compose.material3.ModalBottomSheet
1212import androidx.compose.material3.Text
1313import androidx.compose.material3.contentColorFor
14+ import androidx.compose.material3.rememberModalBottomSheetState
1415import androidx.compose.runtime.Composable
1516import androidx.compose.runtime.CompositionLocalProvider
1617import androidx.compose.runtime.remember
@@ -31,6 +32,7 @@ import androidx.paging.cachedIn
3132import androidx.paging.compose.collectAsLazyPagingItems
3233import kotlinx.coroutines.flow.Flow
3334import kotlinx.coroutines.flow.flowOf
35+ import kotlinx.coroutines.launch
3436import my.nanihadesuka.compose.LazyColumnScrollbar
3537import my.nanihadesuka.compose.ScrollbarSettings
3638import org.schabi.newpipe.R
@@ -46,6 +48,7 @@ import org.schabi.newpipe.ui.theme.md_theme_dark_primary
4648fun CommentRepliesDialog (
4749 parentComment : CommentsInfoItem ,
4850 onDismissRequest : () -> Unit ,
51+ onCommentAuthorOpened : () -> Unit ,
4952) {
5053 val coroutineScope = rememberCoroutineScope()
5154 val commentsFlow = remember {
@@ -56,7 +59,7 @@ fun CommentRepliesDialog(
5659 .cachedIn(coroutineScope)
5760 }
5861
59- CommentRepliesDialog (parentComment, commentsFlow, onDismissRequest)
62+ CommentRepliesDialog (parentComment, commentsFlow, onDismissRequest, onCommentAuthorOpened )
6063}
6164
6265@OptIn(ExperimentalMaterial3Api ::class )
@@ -65,31 +68,48 @@ private fun CommentRepliesDialog(
6568 parentComment : CommentsInfoItem ,
6669 commentsFlow : Flow <PagingData <CommentsInfoItem >>,
6770 onDismissRequest : () -> Unit ,
71+ onCommentAuthorOpened : () -> Unit ,
6872) {
6973 val comments = commentsFlow.collectAsLazyPagingItems()
7074 val nestedScrollInterop = rememberNestedScrollInteropConnection()
71- val state = rememberLazyListState()
75+ val listState = rememberLazyListState()
7276
73- ModalBottomSheet (onDismissRequest = onDismissRequest) {
77+ val coroutineScope = rememberCoroutineScope()
78+ val sheetState = rememberModalBottomSheetState()
79+ val nestedOnCommentAuthorOpened: () -> Unit = {
80+ // also partialExpand any parent dialog
81+ onCommentAuthorOpened()
82+ coroutineScope.launch {
83+ sheetState.partialExpand()
84+ }
85+ }
86+
87+ ModalBottomSheet (
88+ sheetState = sheetState,
89+ onDismissRequest = onDismissRequest,
90+ ) {
7491 CompositionLocalProvider (
7592 // contentColorFor(MaterialTheme.colorScheme.containerColor), i.e. ModalBottomSheet's
7693 // default background color, does not resolve correctly, so need to manually set the
7794 // content color for MaterialTheme.colorScheme.background instead
7895 LocalContentColor provides contentColorFor(MaterialTheme .colorScheme.background)
7996 ) {
8097 LazyColumnScrollbar (
81- state = state ,
98+ state = listState ,
8299 settings = ScrollbarSettings .Default .copy(
83100 thumbSelectedColor = md_theme_dark_primary,
84101 thumbUnselectedColor = Color .Red
85102 )
86103 ) {
87104 LazyColumn (
88105 modifier = Modifier .nestedScroll(nestedScrollInterop),
89- state = state
106+ state = listState
90107 ) {
91108 item {
92- CommentRepliesHeader (comment = parentComment)
109+ CommentRepliesHeader (
110+ comment = parentComment,
111+ onCommentAuthorOpened = nestedOnCommentAuthorOpened,
112+ )
93113 HorizontalDivider (
94114 thickness = 1 .dp,
95115 modifier = Modifier .padding(start = 16 .dp, end = 16 .dp, bottom = 8 .dp)
@@ -127,7 +147,10 @@ private fun CommentRepliesDialog(
127147 }
128148 }
129149 items(comments.itemCount) {
130- Comment (comment = comments[it]!! )
150+ Comment (
151+ comment = comments[it]!! ,
152+ onCommentAuthorOpened = nestedOnCommentAuthorOpened,
153+ )
131154 }
132155 }
133156 }
@@ -159,6 +182,6 @@ private fun CommentRepliesDialogPreview() {
159182 val flow = flowOf(PagingData .from(replies))
160183
161184 AppTheme {
162- CommentRepliesDialog (comment, flow, onDismissRequest = {})
185+ CommentRepliesDialog (comment, flow, onDismissRequest = {}, onCommentAuthorOpened = {} )
163186 }
164187}
0 commit comments