fix(ui): always honor ModalBottomSheet dismiss during AI loading to prevent app freeze

This commit is contained in:
bleack committed 2026-11-29 16:51:21 +01:00
1 parent 7181ea58fc
commit e3bd4d3312
5 files changed
+12 -21

No files matched your search

@@ -66,11 +66,7 @@ fun AdaptMenusForExpiringSheet(
val dayFmt = remember { DateTimeFormatter.ofPattern("EEEE d MMM", Locale.FRENCH) }
ModalBottomSheet(
onDismissRequest = {
if (adaptationState !is MenuAdaptationUiState.Loading) {
onDismiss()
}
},
onDismissRequest = onDismiss,
sheetState = sheetState,
shape = RoundedCornerShape(topStart = 24.dp, topEnd = 24.dp)
) {
@@ -146,6 +146,7 @@ class PlanningViewModel internal constructor(
private val checkedKeysMutex = Mutex()
private var predictionJob: Job? = null
private var adaptationJob: Job? = null
private var receiptScanJob: Job? = null
private val _uiEvents = Channel<UiEvent>(Channel.BUFFERED)
val uiEvents: Flow<UiEvent> = _uiEvents.receiveAsFlow()
@@ -989,7 +990,8 @@ class PlanningViewModel internal constructor(
// ------------------------------------------------------------------------
fun scanReceiptFromUri(uri: Uri) {
viewModelScope.launch {
receiptScanJob?.cancel()
receiptScanJob = viewModelScope.launch {
_receiptScanState.value = ReceiptScanUiState.Scanning
val bitmap = ImageUtils.loadResizedBitmapForAi(getApplication(), uri, maxDimension = 1440)
if (bitmap == null) {
@@ -1101,6 +1103,8 @@ class PlanningViewModel internal constructor(
}
fun dismissReceiptScan() {
receiptScanJob?.cancel()
receiptScanJob = null
_receiptScanState.value = ReceiptScanUiState.Idle
}
@@ -127,11 +127,7 @@ fun PredictWeekSheet(
}
ModalBottomSheet(
onDismissRequest = {
if (predictionState !is WeekPredictionUiState.Loading) {
onDismiss()
}
},
onDismissRequest = onDismiss,
sheetState = sheetState,
shape = RoundedCornerShape(topStart = 24.dp, topEnd = 24.dp)
) {
@@ -359,6 +355,9 @@ fun PredictWeekSheet(
color = MaterialTheme.colorScheme.onSurfaceVariant,
textAlign = TextAlign.Center
)
TextButton(onClick = onDismiss) {
Text("Annuler")
}
}
}
@@ -87,11 +87,7 @@ fun ReceiptReviewSheet(
var alsoCheckShoppingList by remember { mutableStateOf(true) }
ModalBottomSheet(
onDismissRequest = {
if (scanState !is ReceiptScanUiState.Scanning) {
onDismiss()
}
},
onDismissRequest = onDismiss,
sheetState = sheetState,
shape = RoundedCornerShape(topStart = 24.dp, topEnd = 24.dp)
) {
@@ -157,11 +157,7 @@ fun ImportRecipeSheet(
}
ModalBottomSheet(
onDismissRequest = {
if (importState !is RecipeImportUiState.Loading) {
onDismiss()
}
},
onDismissRequest = onDismiss,
sheetState = sheetState,
shape = RoundedCornerShape(topStart = 24.dp, topEnd = 24.dp)
) {