mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 07:13:00 +00:00 
			
		
		
		
	Unexpand bottom sheet dialog when clicking on a channel
This commit is contained in:
		| @@ -53,7 +53,7 @@ import org.schabi.newpipe.util.image.ImageStrategy | ||||
|  | ||||
| @OptIn(ExperimentalFoundationApi::class) | ||||
| @Composable | ||||
| fun Comment(comment: CommentsInfoItem) { | ||||
| fun Comment(comment: CommentsInfoItem, onCommentAuthorOpened: () -> Unit) { | ||||
|     val clipboardManager = LocalClipboardManager.current | ||||
|     val context = LocalContext.current | ||||
|     var isExpanded by rememberSaveable { mutableStateOf(false) } | ||||
| @@ -87,6 +87,7 @@ fun Comment(comment: CommentsInfoItem) { | ||||
|                 .clip(CircleShape) | ||||
|                 .clickable { | ||||
|                     NavigationHelper.openCommentAuthorIfPresent(context, comment) | ||||
|                     onCommentAuthorOpened() | ||||
|                 } | ||||
|         ) | ||||
|  | ||||
| @@ -181,7 +182,11 @@ fun Comment(comment: CommentsInfoItem) { | ||||
|     } | ||||
|  | ||||
|     if (showReplies) { | ||||
|         CommentRepliesDialog(comment, onDismissRequest = { showReplies = false }) | ||||
|         CommentRepliesDialog( | ||||
|             parentComment = comment, | ||||
|             onDismissRequest = { showReplies = false }, | ||||
|             onCommentAuthorOpened = onCommentAuthorOpened, | ||||
|         ) | ||||
|     } | ||||
| } | ||||
|  | ||||
| @@ -257,7 +262,7 @@ private fun CommentPreview( | ||||
| ) { | ||||
|     AppTheme { | ||||
|         Surface(color = MaterialTheme.colorScheme.background) { | ||||
|             Comment(commentsInfoItem) | ||||
|             Comment(commentsInfoItem) {} | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -269,7 +274,7 @@ private fun CommentListPreview() { | ||||
|         Surface(color = MaterialTheme.colorScheme.background) { | ||||
|             Column { | ||||
|                 for (comment in CommentPreviewProvider().values) { | ||||
|                     Comment(comment) | ||||
|                     Comment(comment) {} | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|   | ||||
| @@ -11,6 +11,7 @@ import androidx.compose.material3.MaterialTheme | ||||
| import androidx.compose.material3.ModalBottomSheet | ||||
| import androidx.compose.material3.Text | ||||
| import androidx.compose.material3.contentColorFor | ||||
| import androidx.compose.material3.rememberModalBottomSheetState | ||||
| import androidx.compose.runtime.Composable | ||||
| import androidx.compose.runtime.CompositionLocalProvider | ||||
| import androidx.compose.runtime.remember | ||||
| @@ -31,6 +32,7 @@ import androidx.paging.cachedIn | ||||
| import androidx.paging.compose.collectAsLazyPagingItems | ||||
| import kotlinx.coroutines.flow.Flow | ||||
| import kotlinx.coroutines.flow.flowOf | ||||
| import kotlinx.coroutines.launch | ||||
| import my.nanihadesuka.compose.LazyColumnScrollbar | ||||
| import my.nanihadesuka.compose.ScrollbarSettings | ||||
| import org.schabi.newpipe.R | ||||
| @@ -46,6 +48,7 @@ import org.schabi.newpipe.ui.theme.md_theme_dark_primary | ||||
| fun CommentRepliesDialog( | ||||
|     parentComment: CommentsInfoItem, | ||||
|     onDismissRequest: () -> Unit, | ||||
|     onCommentAuthorOpened: () -> Unit, | ||||
| ) { | ||||
|     val coroutineScope = rememberCoroutineScope() | ||||
|     val commentsFlow = remember { | ||||
| @@ -56,7 +59,7 @@ fun CommentRepliesDialog( | ||||
|             .cachedIn(coroutineScope) | ||||
|     } | ||||
|  | ||||
|     CommentRepliesDialog(parentComment, commentsFlow, onDismissRequest) | ||||
|     CommentRepliesDialog(parentComment, commentsFlow, onDismissRequest, onCommentAuthorOpened) | ||||
| } | ||||
|  | ||||
| @OptIn(ExperimentalMaterial3Api::class) | ||||
| @@ -65,12 +68,26 @@ private fun CommentRepliesDialog( | ||||
|     parentComment: CommentsInfoItem, | ||||
|     commentsFlow: Flow<PagingData<CommentsInfoItem>>, | ||||
|     onDismissRequest: () -> Unit, | ||||
|     onCommentAuthorOpened: () -> Unit, | ||||
| ) { | ||||
|     val comments = commentsFlow.collectAsLazyPagingItems() | ||||
|     val nestedScrollInterop = rememberNestedScrollInteropConnection() | ||||
|     val state = rememberLazyListState() | ||||
|     val listState = rememberLazyListState() | ||||
|  | ||||
|     ModalBottomSheet(onDismissRequest = onDismissRequest) { | ||||
|     val coroutineScope = rememberCoroutineScope() | ||||
|     val sheetState = rememberModalBottomSheetState() | ||||
|     val nestedOnCommentAuthorOpened: () -> Unit = { | ||||
|         // also partialExpand any parent dialog | ||||
|         onCommentAuthorOpened() | ||||
|         coroutineScope.launch { | ||||
|             sheetState.partialExpand() | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     ModalBottomSheet( | ||||
|         sheetState = sheetState, | ||||
|         onDismissRequest = onDismissRequest, | ||||
|     ) { | ||||
|         CompositionLocalProvider( | ||||
|             // contentColorFor(MaterialTheme.colorScheme.containerColor), i.e. ModalBottomSheet's | ||||
|             // default background color, does not resolve correctly, so need to manually set the | ||||
| @@ -78,7 +95,7 @@ private fun CommentRepliesDialog( | ||||
|             LocalContentColor provides contentColorFor(MaterialTheme.colorScheme.background) | ||||
|         ) { | ||||
|             LazyColumnScrollbar( | ||||
|                 state = state, | ||||
|                 state = listState, | ||||
|                 settings = ScrollbarSettings.Default.copy( | ||||
|                     thumbSelectedColor = md_theme_dark_primary, | ||||
|                     thumbUnselectedColor = Color.Red | ||||
| @@ -86,10 +103,13 @@ private fun CommentRepliesDialog( | ||||
|             ) { | ||||
|                 LazyColumn( | ||||
|                     modifier = Modifier.nestedScroll(nestedScrollInterop), | ||||
|                     state = state | ||||
|                     state = listState | ||||
|                 ) { | ||||
|                     item { | ||||
|                         CommentRepliesHeader(comment = parentComment) | ||||
|                         CommentRepliesHeader( | ||||
|                             comment = parentComment, | ||||
|                             onCommentAuthorOpened = nestedOnCommentAuthorOpened, | ||||
|                         ) | ||||
|                         HorizontalDivider( | ||||
|                             thickness = 1.dp, | ||||
|                             modifier = Modifier.padding(start = 16.dp, end = 16.dp, bottom = 8.dp) | ||||
| @@ -127,7 +147,10 @@ private fun CommentRepliesDialog( | ||||
|                             } | ||||
|                         } | ||||
|                         items(comments.itemCount) { | ||||
|                             Comment(comment = comments[it]!!) | ||||
|                             Comment( | ||||
|                                 comment = comments[it]!!, | ||||
|                                 onCommentAuthorOpened = nestedOnCommentAuthorOpened, | ||||
|                             ) | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
| @@ -159,6 +182,6 @@ private fun CommentRepliesDialogPreview() { | ||||
|     val flow = flowOf(PagingData.from(replies)) | ||||
|  | ||||
|     AppTheme { | ||||
|         CommentRepliesDialog(comment, flow, onDismissRequest = {}) | ||||
|         CommentRepliesDialog(comment, flow, onDismissRequest = {}, onCommentAuthorOpened = {}) | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -35,10 +35,13 @@ import org.schabi.newpipe.util.NavigationHelper | ||||
| import org.schabi.newpipe.util.image.ImageStrategy | ||||
|  | ||||
| @Composable | ||||
| fun CommentRepliesHeader(comment: CommentsInfoItem) { | ||||
| fun CommentRepliesHeader(comment: CommentsInfoItem, onCommentAuthorOpened: () -> Unit) { | ||||
|     val context = LocalContext.current | ||||
|  | ||||
|     Column(modifier = Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) { | ||||
|     Column( | ||||
|         modifier = Modifier.padding(16.dp), | ||||
|         verticalArrangement = Arrangement.spacedBy(16.dp), | ||||
|     ) { | ||||
|         Row( | ||||
|             modifier = Modifier.fillMaxWidth(), | ||||
|             horizontalArrangement = Arrangement.SpaceBetween, | ||||
| @@ -48,7 +51,10 @@ fun CommentRepliesHeader(comment: CommentsInfoItem) { | ||||
|                 modifier = Modifier | ||||
|                     .padding(end = 12.dp) | ||||
|                     .clip(CircleShape) | ||||
|                     .clickable { NavigationHelper.openCommentAuthorIfPresent(context, comment) } | ||||
|                     .clickable { | ||||
|                         NavigationHelper.openCommentAuthorIfPresent(context, comment) | ||||
|                         onCommentAuthorOpened() | ||||
|                     } | ||||
|                     .weight(1.0f, true), | ||||
|                 horizontalArrangement = Arrangement.spacedBy(8.dp), | ||||
|                 verticalAlignment = Alignment.CenterVertically, | ||||
| @@ -133,7 +139,7 @@ fun CommentRepliesHeaderPreview() { | ||||
|  | ||||
|     AppTheme { | ||||
|         Surface(color = MaterialTheme.colorScheme.background) { | ||||
|             CommentRepliesHeader(comment) | ||||
|             CommentRepliesHeader(comment) {} | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -111,7 +111,7 @@ private fun CommentSection( | ||||
|  | ||||
|                                 else -> { | ||||
|                                     items(comments.itemCount) { | ||||
|                                         Comment(comment = comments[it]!!) | ||||
|                                         Comment(comment = comments[it]!!) {} | ||||
|                                     } | ||||
|                                 } | ||||
|                             } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Stypox
					Stypox