From 4581f2088511f5b4246ac59149daf518711a1642 Mon Sep 17 00:00:00 2001 From: Stypox Date: Tue, 11 Feb 2025 16:09:03 +0100 Subject: [PATCH] Move long press menu drag handle to its own composable --- .../ui/components/menu/LongPressMenu.kt | 54 ++++++++++--------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/ui/components/menu/LongPressMenu.kt b/app/src/main/java/org/schabi/newpipe/ui/components/menu/LongPressMenu.kt index 7c19daef8..a8ab0e161 100644 --- a/app/src/main/java/org/schabi/newpipe/ui/components/menu/LongPressMenu.kt +++ b/app/src/main/java/org/schabi/newpipe/ui/components/menu/LongPressMenu.kt @@ -115,31 +115,7 @@ fun LongPressMenu( ModalBottomSheet( onDismissRequest, sheetState = sheetState, - dragHandle = { - Box( - modifier = Modifier.fillMaxWidth() - ) { - BottomSheetDefaults.DragHandle( - modifier = Modifier.align(Alignment.Center) - ) - IconButton( - onClick = onEditActions, - modifier = Modifier.align(Alignment.CenterEnd) - ) { - // show a small button here, it's not an important button and it shouldn't - // capture the user attention - Icon( - imageVector = Icons.Default.Settings, - contentDescription = stringResource(R.string.edit), - // same color and height as the DragHandle - tint = MaterialTheme.colorScheme.onSurfaceVariant, - modifier = Modifier - .padding(2.dp) - .size(16.dp), - ) - } - } - }, + dragHandle = { LongPressMenuDragHandle(onEditActions) }, ) { BoxWithConstraints( modifier = Modifier @@ -202,6 +178,34 @@ fun LongPressMenu( } } +@Preview +@Composable +fun LongPressMenuDragHandle(onEditActions: () -> Unit = {}) { + Box( + modifier = Modifier.fillMaxWidth() + ) { + BottomSheetDefaults.DragHandle( + modifier = Modifier.align(Alignment.Center) + ) + IconButton( + onClick = onEditActions, + modifier = Modifier.align(Alignment.CenterEnd) + ) { + // show a small button here, it's not an important button and it shouldn't + // capture the user attention + Icon( + imageVector = Icons.Default.Settings, + contentDescription = stringResource(R.string.edit), + // same color and height as the DragHandle + tint = MaterialTheme.colorScheme.onSurfaceVariant, + modifier = Modifier + .padding(2.dp) + .size(16.dp), + ) + } + } +} + @Composable fun LongPressMenuHeader( item: LongPressable,