Replace Cascade with our own somewhat janky implementation

This commit is contained in:
arkon 2023-05-21 11:02:56 -04:00
parent 44609c494c
commit 5ca7c39751
7 changed files with 118 additions and 102 deletions

View File

@ -237,7 +237,6 @@ dependencies {
implementation(libs.bundles.richtext) implementation(libs.bundles.richtext)
implementation(libs.aboutLibraries.compose) implementation(libs.aboutLibraries.compose)
implementation(libs.bundles.voyager) implementation(libs.bundles.voyager)
implementation(libs.compose.cascade)
implementation(libs.compose.materialmotion) implementation(libs.compose.materialmotion)
implementation(libs.compose.simpleicons) implementation(libs.compose.simpleicons)

View File

@ -9,8 +9,8 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.asPaddingValues import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.only import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.safeContent
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -82,12 +82,15 @@ fun AdaptiveSheet(
content: @Composable (PaddingValues) -> Unit, content: @Composable (PaddingValues) -> Unit,
) { ) {
val isTabletUi = isTabletUi() val isTabletUi = isTabletUi()
val contentPadding = if (isTabletUi) {
PaddingValues()
} else {
WindowInsets.safeContent.only(WindowInsetsSides.Bottom).asPaddingValues()
}
Dialog( Dialog(
onDismissRequest = onDismissRequest, onDismissRequest = onDismissRequest,
properties = DialogProperties( properties = dialogProperties,
usePlatformDefaultWidth = false,
decorFitsSystemWindows = false,
),
) { ) {
AdaptiveSheetImpl( AdaptiveSheetImpl(
isTabletUi = isTabletUi, isTabletUi = isTabletUi,
@ -95,12 +98,12 @@ fun AdaptiveSheet(
enableSwipeDismiss = enableSwipeDismiss, enableSwipeDismiss = enableSwipeDismiss,
onDismissRequest = onDismissRequest, onDismissRequest = onDismissRequest,
) { ) {
val contentPadding = if (isTabletUi) {
PaddingValues()
} else {
WindowInsets.navigationBars.only(WindowInsetsSides.Bottom).asPaddingValues()
}
content(contentPadding) content(contentPadding)
} }
} }
} }
private val dialogProperties = DialogProperties(
usePlatformDefaultWidth = false,
decorFitsSystemWindows = false,
)

View File

@ -1,15 +1,14 @@
package eu.kanade.presentation.components package eu.kanade.presentation.components
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.ColumnScope import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.sizeIn import androidx.compose.foundation.layout.sizeIn
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.MoreVert import androidx.compose.material.icons.outlined.ArrowLeft
import androidx.compose.material.icons.outlined.ArrowRight
import androidx.compose.material.icons.outlined.RadioButtonChecked import androidx.compose.material.icons.outlined.RadioButtonChecked
import androidx.compose.material.icons.outlined.RadioButtonUnchecked import androidx.compose.material.icons.outlined.RadioButtonUnchecked
import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
@ -17,13 +16,13 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.DpOffset import androidx.compose.ui.unit.DpOffset
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.PopupProperties import androidx.compose.ui.window.PopupProperties
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import me.saket.cascade.CascadeColumnScope
import me.saket.cascade.CascadeDropdownMenu
import androidx.compose.material3.DropdownMenu as ComposeDropdownMenu import androidx.compose.material3.DropdownMenu as ComposeDropdownMenu
@Composable @Composable
@ -72,25 +71,29 @@ fun RadioMenuItem(
} }
@Composable @Composable
fun OverflowMenu( fun NestedMenuItem(
content: @Composable CascadeColumnScope.(() -> Unit) -> Unit, text: @Composable () -> Unit,
children: @Composable ColumnScope.(() -> Unit) -> Unit,
) { ) {
var moreExpanded by remember { mutableStateOf(false) } var nestedExpanded by remember { mutableStateOf(false) }
val closeMenu = { moreExpanded = false } val closeMenu = { nestedExpanded = false }
val isLtr = LocalLayoutDirection.current == LayoutDirection.Ltr
Box { DropdownMenuItem(
IconButton(onClick = { moreExpanded = !moreExpanded }) { text = text,
onClick = { nestedExpanded = true },
trailingIcon = {
Icon( Icon(
imageVector = Icons.Outlined.MoreVert, imageVector = if (isLtr) Icons.Outlined.ArrowRight else Icons.Outlined.ArrowLeft,
contentDescription = stringResource(R.string.abc_action_menu_overflow_description), contentDescription = null,
) )
} },
CascadeDropdownMenu( )
expanded = moreExpanded,
onDismissRequest = closeMenu, DropdownMenu(
offset = DpOffset(8.dp, (-56).dp), expanded = nestedExpanded,
) { onDismissRequest = closeMenu,
content(closeMenu) ) {
} children(closeMenu)
} }
} }

View File

@ -1,6 +1,5 @@
package eu.kanade.presentation.manga.components package eu.kanade.presentation.manga.components
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.ArrowBack import androidx.compose.material.icons.outlined.ArrowBack
@ -18,8 +17,10 @@ import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.surfaceColorAtElevation import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha import androidx.compose.ui.draw.alpha
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
@ -89,27 +90,28 @@ fun MangaToolbar(
), ),
) )
} else { } else {
var downloadExpanded by remember { mutableStateOf(false) }
if (onClickDownload != null) { if (onClickDownload != null) {
val (downloadExpanded, onDownloadExpanded) = remember { mutableStateOf(false) } val onDismissRequest = { downloadExpanded = false }
Box { DownloadDropdownMenu(
IconButton(onClick = { onDownloadExpanded(!downloadExpanded) }) { expanded = downloadExpanded,
Icon( onDismissRequest = onDismissRequest,
imageVector = Icons.Outlined.Download, onDownloadClicked = onClickDownload,
contentDescription = stringResource(R.string.manga_download), )
)
}
val onDismissRequest = { onDownloadExpanded(false) }
DownloadDropdownMenu(
expanded = downloadExpanded,
onDismissRequest = onDismissRequest,
onDownloadClicked = onClickDownload,
)
}
} }
val filterTint = if (hasFilters) MaterialTheme.colorScheme.active else LocalContentColor.current val filterTint = if (hasFilters) MaterialTheme.colorScheme.active else LocalContentColor.current
AppBarActions( AppBarActions(
actions = buildList { actions = buildList {
if (onClickDownload != null) {
add(
AppBar.Action(
title = stringResource(R.string.manga_download),
icon = Icons.Outlined.Download,
onClick = { downloadExpanded = !downloadExpanded },
),
)
}
add( add(
AppBar.Action( AppBar.Action(
title = stringResource(R.string.action_filter), title = stringResource(R.string.action_filter),

View File

@ -12,6 +12,8 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.PlayArrow import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material.icons.outlined.Pause import androidx.compose.material.icons.outlined.Pause
import androidx.compose.material.icons.outlined.Sort
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
@ -47,7 +49,9 @@ import cafe.adriel.voyager.core.model.rememberScreenModel
import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow import cafe.adriel.voyager.navigator.currentOrThrow
import eu.kanade.presentation.components.AppBar import eu.kanade.presentation.components.AppBar
import eu.kanade.presentation.components.OverflowMenu import eu.kanade.presentation.components.AppBarActions
import eu.kanade.presentation.components.DropdownMenu
import eu.kanade.presentation.components.NestedMenuItem
import eu.kanade.presentation.util.Screen import eu.kanade.presentation.util.Screen
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.DownloadListBinding import eu.kanade.tachiyomi.databinding.DownloadListBinding
@ -120,70 +124,77 @@ object DownloadQueueScreen : Screen() {
navigateUp = navigator::pop, navigateUp = navigator::pop,
actions = { actions = {
if (downloadList.isNotEmpty()) { if (downloadList.isNotEmpty()) {
OverflowMenu { closeMenu -> var sortExpanded by remember { mutableStateOf(false) }
DropdownMenuItem( val onDismissRequest = { sortExpanded = false }
text = { Text(text = stringResource(R.string.action_reorganize_by)) }, DropdownMenu(
children = { expanded = sortExpanded,
onDismissRequest = onDismissRequest,
) {
NestedMenuItem(
text = { Text(text = stringResource(R.string.action_order_by_upload_date)) },
children = { closeMenu ->
DropdownMenuItem( DropdownMenuItem(
text = { Text(text = stringResource(R.string.action_order_by_upload_date)) }, text = { Text(text = stringResource(R.string.action_newest)) },
children = { onClick = {
androidx.compose.material3.DropdownMenuItem( screenModel.reorderQueue(
text = { Text(text = stringResource(R.string.action_newest)) }, { it.download.chapter.dateUpload },
onClick = { true,
screenModel.reorderQueue(
{ it.download.chapter.dateUpload },
true,
)
closeMenu()
},
)
androidx.compose.material3.DropdownMenuItem(
text = { Text(text = stringResource(R.string.action_oldest)) },
onClick = {
screenModel.reorderQueue(
{ it.download.chapter.dateUpload },
false,
)
closeMenu()
},
) )
closeMenu()
}, },
) )
DropdownMenuItem( DropdownMenuItem(
text = { Text(text = stringResource(R.string.action_order_by_chapter_number)) }, text = { Text(text = stringResource(R.string.action_oldest)) },
children = { onClick = {
androidx.compose.material3.DropdownMenuItem( screenModel.reorderQueue(
text = { Text(text = stringResource(R.string.action_asc)) }, { it.download.chapter.dateUpload },
onClick = { false,
screenModel.reorderQueue(
{ it.download.chapter.chapterNumber },
false,
)
closeMenu()
},
)
androidx.compose.material3.DropdownMenuItem(
text = { Text(text = stringResource(R.string.action_desc)) },
onClick = {
screenModel.reorderQueue(
{ it.download.chapter.chapterNumber },
true,
)
closeMenu()
},
) )
closeMenu()
}, },
) )
}, },
) )
androidx.compose.material3.DropdownMenuItem( NestedMenuItem(
text = { Text(text = stringResource(R.string.action_cancel_all)) }, text = { Text(text = stringResource(R.string.action_order_by_chapter_number)) },
onClick = { children = { closeMenu ->
screenModel.clearQueue() DropdownMenuItem(
closeMenu() text = { Text(text = stringResource(R.string.action_asc)) },
onClick = {
screenModel.reorderQueue(
{ it.download.chapter.chapterNumber },
false,
)
closeMenu()
},
)
DropdownMenuItem(
text = { Text(text = stringResource(R.string.action_desc)) },
onClick = {
screenModel.reorderQueue(
{ it.download.chapter.chapterNumber },
true,
)
closeMenu()
},
)
}, },
) )
} }
AppBarActions(
listOf(
AppBar.Action(
title = stringResource(R.string.action_sort),
icon = Icons.Outlined.Sort,
onClick = { sortExpanded = true },
),
AppBar.OverflowAction(
title = stringResource(R.string.action_cancel_all),
onClick = { screenModel.clearQueue() },
),
),
)
} }
}, },
scrollBehavior = scrollBehavior, scrollBehavior = scrollBehavior,

View File

@ -60,7 +60,6 @@ flexible-adapter-ui = "com.github.arkon.FlexibleAdapter:flexible-adapter-ui:c801
photoview = "com.github.chrisbanes:PhotoView:2.3.0" photoview = "com.github.chrisbanes:PhotoView:2.3.0"
directionalviewpager = "com.github.tachiyomiorg:DirectionalViewPager:1.0.0" directionalviewpager = "com.github.tachiyomiorg:DirectionalViewPager:1.0.0"
insetter = "dev.chrisbanes.insetter:insetter:0.6.1" insetter = "dev.chrisbanes.insetter:insetter:0.6.1"
compose-cascade = "me.saket.cascade:cascade-compose:2.0.0-rc02"
compose-materialmotion = "io.github.fornewid:material-motion-compose-core:0.12.3" compose-materialmotion = "io.github.fornewid:material-motion-compose-core:0.12.3"
compose-simpleicons = "br.com.devsrsouza.compose.icons.android:simple-icons:1.0.0" compose-simpleicons = "br.com.devsrsouza.compose.icons.android:simple-icons:1.0.0"

View File

@ -120,7 +120,6 @@
<string name="action_cancel_all">Cancel all</string> <string name="action_cancel_all">Cancel all</string>
<string name="cancel_all_for_series">Cancel all for this series</string> <string name="cancel_all_for_series">Cancel all for this series</string>
<string name="action_sort">Sort</string> <string name="action_sort">Sort</string>
<string name="action_reorganize_by">Reorder</string>
<string name="action_order_by_upload_date">By upload date</string> <string name="action_order_by_upload_date">By upload date</string>
<string name="action_order_by_chapter_number">By chapter number</string> <string name="action_order_by_chapter_number">By chapter number</string>
<string name="action_newest">Newest</string> <string name="action_newest">Newest</string>