Fix glass style in meal plan editor

This commit is contained in:
2026-06-06 10:28:05 +02:00
parent 11ea98e452
commit ade14e28fc
2 changed files with 64 additions and 67 deletions

View File

@@ -14,7 +14,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
@@ -37,9 +36,6 @@ import com.composables.core.Scrim
import com.composables.core.Sheet import com.composables.core.Sheet
import com.composables.core.SheetDetent import com.composables.core.SheetDetent
import com.composables.core.rememberModalBottomSheetState import com.composables.core.rememberModalBottomSheetState
import dev.ulfrx.recipe.ui.components.glass.GlassBackdropSource
import dev.ulfrx.recipe.ui.components.glass.LocalGlassBackdropState
import dev.ulfrx.recipe.ui.components.glass.rememberGlassBackdropState
import dev.ulfrx.recipe.ui.theme.RecipeTheme import dev.ulfrx.recipe.ui.theme.RecipeTheme
import org.jetbrains.compose.resources.stringResource import org.jetbrains.compose.resources.stringResource
import recipe.composeapp.generated.resources.Res import recipe.composeapp.generated.resources.Res
@@ -88,25 +84,12 @@ fun <T : NavKey> RecipeBottomSheet(
@Composable @Composable
private fun BottomSheetScope.SheetBody(content: @Composable BoxScope.() -> Unit) { private fun BottomSheetScope.SheetBody(content: @Composable BoxScope.() -> Unit) {
val backdrop = rememberGlassBackdropState() Box(modifier = Modifier.fillMaxWidth().fillMaxHeight(SHEET_HEIGHT_FRACTION)) {
val spacing = RecipeTheme.spacing Box(modifier = Modifier.fillMaxSize(), content = content)
CompositionLocalProvider(LocalGlassBackdropState provides backdrop) { SheetHandle(
Box( modifier = Modifier.align(Alignment.TopCenter).padding(top = RecipeTheme.spacing.sm),
modifier = )
Modifier
.fillMaxWidth()
.fillMaxHeight(SHEET_HEIGHT_FRACTION)
.background(RecipeTheme.colors.background),
) {
GlassBackdropSource(state = backdrop, modifier = Modifier.fillMaxSize()) {
Box(modifier = Modifier.fillMaxSize(), content = content)
}
SheetHandle(
modifier = Modifier.align(Alignment.TopCenter).padding(top = spacing.sm),
)
}
} }
} }

View File

@@ -1,5 +1,6 @@
package dev.ulfrx.recipe.ui.screens.mealplaneditor package dev.ulfrx.recipe.ui.screens.mealplaneditor
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
@@ -8,6 +9,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.BasicText import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
@@ -17,6 +19,9 @@ import com.composables.icons.lucide.ArrowLeft
import com.composables.icons.lucide.Lucide import com.composables.icons.lucide.Lucide
import com.composables.icons.lucide.Plus import com.composables.icons.lucide.Plus
import dev.ulfrx.recipe.ui.components.glass.CircleGlassButton import dev.ulfrx.recipe.ui.components.glass.CircleGlassButton
import dev.ulfrx.recipe.ui.components.glass.GlassBackdropSource
import dev.ulfrx.recipe.ui.components.glass.LocalGlassBackdropState
import dev.ulfrx.recipe.ui.components.glass.rememberGlassBackdropState
import dev.ulfrx.recipe.ui.theme.RecipeTheme import dev.ulfrx.recipe.ui.theme.RecipeTheme
import org.jetbrains.compose.resources.stringResource import org.jetbrains.compose.resources.stringResource
import recipe.composeapp.generated.resources.Res import recipe.composeapp.generated.resources.Res
@@ -30,58 +35,67 @@ internal fun MealPlanEditorScreen(
onBack: () -> Unit, onBack: () -> Unit,
onConfirm: (PlannedMealUi) -> Unit, onConfirm: (PlannedMealUi) -> Unit,
) { ) {
val backdrop = rememberGlassBackdropState()
val state by viewModel.state.collectAsStateWithLifecycle() val state by viewModel.state.collectAsStateWithLifecycle()
val spacing = RecipeTheme.spacing val spacing = RecipeTheme.spacing
Box(modifier = Modifier.fillMaxSize()) { CompositionLocalProvider(LocalGlassBackdropState provides backdrop) {
when (val s = state) { Box(
is MealPlanEditorState.Editing -> { modifier =
MealPlanEditorContent( Modifier
editing = s, .fillMaxSize()
catalog = sampleAddableIngredients, .background(RecipeTheme.colors.background),
topChromeInset = TopActionsTopInset, ) {
topChromeHeight = TopPillHeight, when (val s = state) {
onSelectDate = viewModel::selectDate, is MealPlanEditorState.Editing -> {
onSetCalendarExpanded = viewModel::setCalendarExpanded, GlassBackdropSource(state = backdrop, modifier = Modifier.fillMaxSize()) {
onSelectSlot = viewModel::selectSlot, MealPlanEditorContent(
onSetServings = viewModel::setServings, editing = s,
onSelectSubstitution = viewModel::selectSubstitution, catalog = sampleAddableIngredients,
onRemoveRecipeIngredient = viewModel::removeRecipeIngredient, topChromeInset = TopActionsTopInset,
onRemoveAddedIngredient = viewModel::removeAddedIngredient, topChromeHeight = TopPillHeight,
onRestoreRemoved = viewModel::restoreRemovedIngredients, onSelectDate = viewModel::selectDate,
onAddIngredient = viewModel::addIngredient, onSetCalendarExpanded = viewModel::setCalendarExpanded,
) onSelectSlot = viewModel::selectSlot,
onSetServings = viewModel::setServings,
onSelectSubstitution = viewModel::selectSubstitution,
onRemoveRecipeIngredient = viewModel::removeRecipeIngredient,
onRemoveAddedIngredient = viewModel::removeAddedIngredient,
onRestoreRemoved = viewModel::restoreRemovedIngredients,
onAddIngredient = viewModel::addIngredient,
)
}
EditorChromeRow( EditorChromeRow(
showConfirm = true, showConfirm = true,
onBack = onBack, onBack = onBack,
onConfirm = { viewModel.confirm()?.let(onConfirm) }, onConfirm = { viewModel.confirm()?.let(onConfirm) },
modifier = modifier =
Modifier Modifier
.align(Alignment.TopCenter) .align(Alignment.TopCenter)
.fillMaxWidth() .fillMaxWidth()
.padding(top = TopActionsTopInset, start = spacing.lg, end = spacing.lg), .padding(top = TopActionsTopInset, start = spacing.lg, end = spacing.lg),
)
}
MealPlanEditorState.NotFound -> {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
BasicText(
text = stringResource(Res.string.meal_plan_editor_not_found),
style = RecipeTheme.typography.body,
) )
} }
EditorChromeRow( MealPlanEditorState.NotFound -> {
showConfirm = false, BasicText(
onBack = onBack, text = stringResource(Res.string.meal_plan_editor_not_found),
onConfirm = {}, style = RecipeTheme.typography.body,
modifier = modifier = Modifier.align(Alignment.Center),
Modifier )
.align(Alignment.TopCenter)
.fillMaxWidth() EditorChromeRow(
.padding(top = TopActionsTopInset, start = spacing.lg, end = spacing.lg), showConfirm = false,
) onBack = onBack,
onConfirm = {},
modifier =
Modifier
.align(Alignment.TopCenter)
.fillMaxWidth()
.padding(top = TopActionsTopInset, start = spacing.lg, end = spacing.lg),
)
}
} }
} }
} }