1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package eu.kanade.presentation.components
- import androidx.compose.foundation.layout.ColumnScope
- import androidx.compose.foundation.layout.sizeIn
- import androidx.compose.material.icons.Icons
- import androidx.compose.material.icons.automirrored.outlined.ArrowRight
- import androidx.compose.material.icons.outlined.RadioButtonChecked
- import androidx.compose.material.icons.outlined.RadioButtonUnchecked
- import androidx.compose.material3.DropdownMenuItem
- import androidx.compose.material3.Icon
- import androidx.compose.material3.MaterialTheme
- import androidx.compose.runtime.Composable
- import androidx.compose.runtime.getValue
- import androidx.compose.runtime.mutableStateOf
- import androidx.compose.runtime.remember
- import androidx.compose.runtime.setValue
- import androidx.compose.ui.Modifier
- import androidx.compose.ui.unit.DpOffset
- import androidx.compose.ui.unit.dp
- import androidx.compose.ui.window.PopupProperties
- import tachiyomi.i18n.MR
- import tachiyomi.presentation.core.i18n.stringResource
- import androidx.compose.material3.DropdownMenu as ComposeDropdownMenu
- @Composable
- fun DropdownMenu(
- expanded: Boolean,
- onDismissRequest: () -> Unit,
- modifier: Modifier = Modifier,
- offset: DpOffset = DpOffset(8.dp, (-56).dp),
- properties: PopupProperties = PopupProperties(focusable = true),
- content: @Composable ColumnScope.() -> Unit,
- ) {
- ComposeDropdownMenu(
- expanded = expanded,
- onDismissRequest = onDismissRequest,
- modifier = modifier.sizeIn(minWidth = 196.dp, maxWidth = 196.dp),
- offset = offset,
- properties = properties,
- content = content,
- )
- }
- @Composable
- fun RadioMenuItem(
- text: @Composable () -> Unit,
- isChecked: Boolean,
- onClick: () -> Unit,
- ) {
- DropdownMenuItem(
- text = text,
- onClick = onClick,
- trailingIcon = {
- if (isChecked) {
- Icon(
- imageVector = Icons.Outlined.RadioButtonChecked,
- contentDescription = stringResource(MR.strings.selected),
- tint = MaterialTheme.colorScheme.primary,
- )
- } else {
- Icon(
- imageVector = Icons.Outlined.RadioButtonUnchecked,
- contentDescription = stringResource(MR.strings.not_selected),
- )
- }
- },
- )
- }
- @Composable
- fun NestedMenuItem(
- text: @Composable () -> Unit,
- children: @Composable ColumnScope.(() -> Unit) -> Unit,
- ) {
- var nestedExpanded by remember { mutableStateOf(false) }
- val closeMenu = { nestedExpanded = false }
- DropdownMenuItem(
- text = text,
- onClick = { nestedExpanded = true },
- trailingIcon = {
- Icon(
- imageVector = Icons.AutoMirrored.Outlined.ArrowRight,
- contentDescription = null,
- )
- },
- )
- DropdownMenu(
- expanded = nestedExpanded,
- onDismissRequest = closeMenu,
- ) {
- children(closeMenu)
- }
- }
|