update AppFabMenu to support optional titles and expand FABs in MainVocabularyScreen and VocabularyMenu

This commit is contained in:
jonasgaudian
2026-02-14 00:25:23 +01:00
parent 73cb3e1855
commit 37d8518e50
7 changed files with 41 additions and 16 deletions

View File

@@ -12,7 +12,7 @@ sealed class WidgetType(val id: String, @param:StringRes val titleRes: Int) {
data object StartButtons : WidgetType("start_buttons", R.string.label_start_exercise)
data object AllVocabulary : WidgetType("all_vocabulary", R.string.label_all_vocabulary)
data object DueToday : WidgetType("due_today", R.string.title_widget_due_today)
data object CategoryProgress : WidgetType("category_progress", R.string.title_widget_category_progress)
data object CategoryProgress : WidgetType("category_progress", R.string.label_categories)
data object WeeklyActivityChart : WidgetType("weekly_activity_chart", R.string.text_widget_title_weekly_activity)
data object Levels : WidgetType("category_stats", R.string.levels)

View File

@@ -54,7 +54,8 @@ data class FabMenuItem(
@Composable
fun AppFabMenu(
items: List<FabMenuItem>,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
title: String? = null
) {
var isMenuExpanded by remember { mutableStateOf(false) }
@@ -67,6 +68,10 @@ fun AppFabMenu(
label = "fabRotation"
)
// Only rotate the FAB itself if there's no title, otherwise rotate just the icon
val fabRotationAngle = if (title == null) rotationAngle else 0f
val iconRotationAngle = if (title != null) rotationAngle else 0f
Column(
modifier = modifier,
horizontalAlignment = Alignment.End,
@@ -97,16 +102,29 @@ fun AppFabMenu(
FloatingActionButton(
onClick = { isMenuExpanded = !isMenuExpanded },
modifier = Modifier.rotate(rotationAngle),
modifier = Modifier.rotate(fabRotationAngle),
shape = RoundedCornerShape(16.dp),
containerColor = MaterialTheme.colorScheme.primary,
contentColor = MaterialTheme.colorScheme.onPrimary,
elevation = FloatingActionButtonDefaults.elevation(defaultElevation = ComponentDefaults.DefaultElevation)
) {
Icon(
imageVector = AppIcons.Add,
contentDescription = stringResource(R.string.cd_toggle_menu)
)
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier.padding(horizontal = 16.dp)
) {
Icon(
imageVector = AppIcons.Add,
contentDescription = stringResource(R.string.cd_toggle_menu),
modifier = Modifier.rotate(iconRotationAngle)
)
if (title != null) {
Text(
text = title,
style = MaterialTheme.typography.labelLarge
)
}
}
}
}
}

View File

@@ -48,7 +48,7 @@ fun VocabularyMenu(
)
)
AppFabMenu(items = menuItems, modifier = modifier)
AppFabMenu(items = menuItems, modifier = modifier, title = stringResource(R.string.label_add_vocabulary))
if (showAddVocabularyDialog) {
AddVocabularyDialog(

View File

@@ -382,7 +382,7 @@ fun MainVocabularyScreen(
var menuHeightPx by remember { mutableIntStateOf(0) }
val density = LocalDensity.current
val menuHeightDp = (menuHeightPx / density.density).dp
val animatedBottomPadding by animateDpAsState(targetValue = 16.dp + 8.dp + menuHeightDp, label = "fabBottomPadding")
val animatedBottomPadding by animateDpAsState(targetValue = 16.dp + 8.dp + menuHeightDp, label = "FBottomPadding")
Column(
modifier = Modifier
@@ -402,10 +402,20 @@ fun MainVocabularyScreen(
.align(Alignment.BottomEnd)
.padding(end = 16.dp, bottom = animatedBottomPadding)
) {
Icon(
imageVector = AppIcons.Quiz,
contentDescription = stringResource(R.string.cd_start_exercise)
)
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp),
modifier = Modifier.padding(horizontal = 16.dp)
) {
Icon(
imageVector = AppIcons.Quiz,
contentDescription = null
)
Text(
text = stringResource(R.string.label_start_exercise),
style = MaterialTheme.typography.labelLarge
)
}
}
}
}