Skip to content

Commit 800961c

Browse files
committed
Unexpand bottom sheet dialog when clicking on a channel
1 parent 9d8a79b commit 800961c

4 files changed

Lines changed: 51 additions & 17 deletions

File tree

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import org.schabi.newpipe.util.image.ImageStrategy
5353

5454
@OptIn(ExperimentalFoundationApi::class)
5555
@Composable
56-
fun Comment(comment: CommentsInfoItem) {
56+
fun Comment(comment: CommentsInfoItem, onCommentAuthorOpened: () -> Unit) {
5757
val clipboardManager = LocalClipboardManager.current
5858
val context = LocalContext.current
5959
var isExpanded by rememberSaveable { mutableStateOf(false) }
@@ -87,6 +87,7 @@ fun Comment(comment: CommentsInfoItem) {
8787
.clip(CircleShape)
8888
.clickable {
8989
NavigationHelper.openCommentAuthorIfPresent(context, comment)
90+
onCommentAuthorOpened()
9091
}
9192
)
9293

@@ -181,7 +182,11 @@ fun Comment(comment: CommentsInfoItem) {
181182
}
182183

183184
if (showReplies) {
184-
CommentRepliesDialog(comment, onDismissRequest = { showReplies = false })
185+
CommentRepliesDialog(
186+
parentComment = comment,
187+
onDismissRequest = { showReplies = false },
188+
onCommentAuthorOpened = onCommentAuthorOpened,
189+
)
185190
}
186191
}
187192

@@ -257,7 +262,7 @@ private fun CommentPreview(
257262
) {
258263
AppTheme {
259264
Surface(color = MaterialTheme.colorScheme.background) {
260-
Comment(commentsInfoItem)
265+
Comment(commentsInfoItem) {}
261266
}
262267
}
263268
}
@@ -269,7 +274,7 @@ private fun CommentListPreview() {
269274
Surface(color = MaterialTheme.colorScheme.background) {
270275
Column {
271276
for (comment in CommentPreviewProvider().values) {
272-
Comment(comment)
277+
Comment(comment) {}
273278
}
274279
}
275280
}

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

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import androidx.compose.material3.MaterialTheme
1111
import androidx.compose.material3.ModalBottomSheet
1212
import androidx.compose.material3.Text
1313
import androidx.compose.material3.contentColorFor
14+
import androidx.compose.material3.rememberModalBottomSheetState
1415
import androidx.compose.runtime.Composable
1516
import androidx.compose.runtime.CompositionLocalProvider
1617
import androidx.compose.runtime.remember
@@ -31,6 +32,7 @@ import androidx.paging.cachedIn
3132
import androidx.paging.compose.collectAsLazyPagingItems
3233
import kotlinx.coroutines.flow.Flow
3334
import kotlinx.coroutines.flow.flowOf
35+
import kotlinx.coroutines.launch
3436
import my.nanihadesuka.compose.LazyColumnScrollbar
3537
import my.nanihadesuka.compose.ScrollbarSettings
3638
import org.schabi.newpipe.R
@@ -46,6 +48,7 @@ import org.schabi.newpipe.ui.theme.md_theme_dark_primary
4648
fun 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
}

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ import org.schabi.newpipe.util.NavigationHelper
3535
import org.schabi.newpipe.util.image.ImageStrategy
3636

3737
@Composable
38-
fun CommentRepliesHeader(comment: CommentsInfoItem) {
38+
fun CommentRepliesHeader(comment: CommentsInfoItem, onCommentAuthorOpened: () -> Unit) {
3939
val context = LocalContext.current
4040

41-
Column(modifier = Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) {
41+
Column(
42+
modifier = Modifier.padding(16.dp),
43+
verticalArrangement = Arrangement.spacedBy(16.dp),
44+
) {
4245
Row(
4346
modifier = Modifier.fillMaxWidth(),
4447
horizontalArrangement = Arrangement.SpaceBetween,
@@ -48,7 +51,10 @@ fun CommentRepliesHeader(comment: CommentsInfoItem) {
4851
modifier = Modifier
4952
.padding(end = 12.dp)
5053
.clip(CircleShape)
51-
.clickable { NavigationHelper.openCommentAuthorIfPresent(context, comment) }
54+
.clickable {
55+
NavigationHelper.openCommentAuthorIfPresent(context, comment)
56+
onCommentAuthorOpened()
57+
}
5258
.weight(1.0f, true),
5359
horizontalArrangement = Arrangement.spacedBy(8.dp),
5460
verticalAlignment = Alignment.CenterVertically,
@@ -133,7 +139,7 @@ fun CommentRepliesHeaderPreview() {
133139

134140
AppTheme {
135141
Surface(color = MaterialTheme.colorScheme.background) {
136-
CommentRepliesHeader(comment)
142+
CommentRepliesHeader(comment) {}
137143
}
138144
}
139145
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private fun CommentSection(
111111

112112
else -> {
113113
items(comments.itemCount) {
114-
Comment(comment = comments[it]!!)
114+
Comment(comment = comments[it]!!) {}
115115
}
116116
}
117117
}

0 commit comments

Comments
 (0)