Skip to content

Commit 88327b5

Browse files
committed
refactor(card-list): replace create sheet with floating menu
1 parent 5d5f325 commit 88327b5

File tree

1 file changed

+39
-43
lines changed

1 file changed

+39
-43
lines changed

app/src/main/java/de/pawcode/cardstore/ui/screens/CardListScreen.kt

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import androidx.compose.material3.ExperimentalMaterial3Api
3030
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
3131
import androidx.compose.material3.ExtendedFloatingActionButton
3232
import androidx.compose.material3.FilledIconButton
33+
import androidx.compose.material3.FloatingActionButtonMenu
34+
import androidx.compose.material3.FloatingActionButtonMenuItem
3335
import androidx.compose.material3.Icon
3436
import androidx.compose.material3.IconButtonDefaults
3537
import androidx.compose.material3.ModalBottomSheet
@@ -189,7 +191,6 @@ fun CardListScreenComponent(
189191
val cardShareSheetState = rememberModalBottomSheetState()
190192
val cardImportSheetState = rememberModalBottomSheetState()
191193
val cardOptionSheetState = rememberModalBottomSheetState()
192-
val cardCreateSheetState = rememberModalBottomSheetState()
193194

194195
var selectedLabel by remember { mutableStateOf<String?>(null) }
195196

@@ -278,13 +279,43 @@ fun CardListScreenComponent(
278279
)
279280
},
280281
floatingActionButton = {
281-
ExtendedFloatingActionButton(
282-
onClick = { showCardCreateSheet = true },
283-
text = { Text(stringResource(R.string.cards_new)) },
284-
icon = {
285-
Icon(Icons.Filled.AddCard, contentDescription = stringResource(R.string.cards_new))
286-
},
287-
)
282+
FloatingActionButtonMenu(
283+
expanded = showCardCreateSheet,
284+
button = {
285+
ExtendedFloatingActionButton(
286+
onClick = { showCardCreateSheet = true },
287+
text = { Text(stringResource(R.string.cards_new)) },
288+
icon = {
289+
Icon(Icons.Filled.AddCard, contentDescription = stringResource(R.string.cards_new))
290+
},
291+
)
292+
}
293+
) {
294+
FloatingActionButtonMenuItem(
295+
onClick = {
296+
showBarcodeScanner = true
297+
showCardCreateSheet = false
298+
},
299+
text = { Text(stringResource(R.string.scan_barcode)) },
300+
icon = { Icon(Icons.Outlined.QrCodeScanner, contentDescription = null) },
301+
)
302+
FloatingActionButtonMenuItem(
303+
onClick = {
304+
showPkpassPicker = true
305+
showCardCreateSheet = false
306+
},
307+
text = { Text(stringResource(R.string.card_create_pkpass)) },
308+
icon = { Icon(Icons.Outlined.FileOpen, contentDescription = null) },
309+
)
310+
FloatingActionButtonMenuItem(
311+
onClick = {
312+
onCreateCard(null, null)
313+
showCardCreateSheet = false
314+
},
315+
text = { Text(stringResource(R.string.card_create_manual)) },
316+
icon = { Icon(Icons.Filled.Edit, contentDescription = null) },
317+
)
318+
}
288319
},
289320
) { innerPadding ->
290321
Column(modifier = Modifier.padding(innerPadding).padding(horizontal = 8.dp)) {
@@ -395,41 +426,6 @@ fun CardListScreenComponent(
395426
}
396427
}
397428

398-
if (showCardCreateSheet) {
399-
ModalBottomSheet(
400-
sheetState = cardCreateSheetState,
401-
dragHandle = {},
402-
onDismissRequest = { showCardCreateSheet = false },
403-
) {
404-
OptionSheet(
405-
Option(
406-
label = stringResource(R.string.scan_barcode),
407-
icon = Icons.Outlined.QrCodeScanner,
408-
onClick = {
409-
showBarcodeScanner = true
410-
showCardCreateSheet = false
411-
},
412-
),
413-
Option(
414-
label = stringResource(R.string.card_create_pkpass),
415-
icon = Icons.Outlined.FileOpen,
416-
onClick = {
417-
showPkpassPicker = true
418-
showCardCreateSheet = false
419-
},
420-
),
421-
Option(
422-
label = stringResource(R.string.card_create_manual),
423-
icon = Icons.Filled.Edit,
424-
onClick = {
425-
onCreateCard(null, null)
426-
showCardCreateSheet = false
427-
},
428-
),
429-
)
430-
}
431-
}
432-
433429
openDeleteDialog?.let {
434430
ConfirmDialog(
435431
onDismissRequest = { openDeleteDialog = null },

0 commit comments

Comments
 (0)