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