Skip to content

Commit

Permalink
fix: Images reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
Lastaapps committed Jan 18, 2025
1 parent ea36f21 commit 8cfda3c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved
* Copyright 2025, Petr Laštovička as Lasta apps, All rights reserved
*
* This file is part of Menza.
*
Expand Down Expand Up @@ -218,6 +218,25 @@ data class Dish(
ingredients = persistentListOf(),
isActive = true,
)
val dishMisterious =
Dish(
menza = MenzaType.Testing.Kocourkov,
id = DishID.testing(),
language = Czech,
amount = "??? g",
name = "Záludnost",
priceDiscounted = 42.0f,
priceNormal = 69.0f,
allergens = persistentListOf(1, 2, 3),
photoLink = "https://blbost.kravina.haha",
pictogram = persistentListOf(),
servingPlaces =
persistentListOf(
ServingPlace("Magistrát", "J"),
),
ingredients = persistentListOf(),
isActive = true,
)
val desertKrtkuvDort =
Dish(
menza = MenzaType.Testing.Kocourkov,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ data class DishCategory(
Dish.Mock.dishTux,
Dish.Mock.dishKunda,
Dish.Mock.dishMaxipes,
Dish.Mock.dishMisterious,
),
)
val dezerty =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved
* Copyright 2025, Petr Laštovička as Lasta apps, All rights reserved
*
* This file is part of Menza.
*
Expand Down Expand Up @@ -51,7 +51,6 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import coil3.Extras
import coil3.compose.SubcomposeAsyncImage
import coil3.request.CachePolicy
import coil3.request.ImageRequest.Builder
Expand Down Expand Up @@ -125,7 +124,7 @@ internal fun DishImage(
with(Builder(LocalContext.current)) {
diskCacheKey(photoLink)
memoryCacheKey(photoLink)
extras[Extras.Key("retry_hash")] = retryHash
memoryCacheKeyExtra("retry_hash", retryHash.toString())

// if user is not on a metered network, images are going to be loaded from cache
if (!canDownload) {
Expand Down Expand Up @@ -235,9 +234,9 @@ private fun DishImageSupplementPreview() =
remember { Random.nextInt() },
color = it,
modifier =
Modifier
.padding(12.dp)
.aspectRatio(DishImageTokens.ASPECT_RATIO),
Modifier
.padding(12.dp)
.aspectRatio(DishImageTokens.ASPECT_RATIO),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,12 @@ private fun DishContent(
HorizontalMultiBrowseCarousel(
state = carouselState,
preferredItemWidth = preferredItemSize,
// TODO revert
// minSmallItemWidth = 64.dp,
// maxSmallItemWidth = 128.dp,
minSmallItemWidth = 20.dp,
maxSmallItemWidth = 40.dp,
minSmallItemWidth = 64.dp,
maxSmallItemWidth = 128.dp,
itemSpacing = Padding.MidSmall,
modifier =
Modifier
.fillMaxWidth(),
Modifier
.fillMaxWidth(),
// .animateItem(),
) { index ->
val dish = category.dishList[index]
Expand Down Expand Up @@ -346,49 +343,48 @@ private fun DishItem(
val shape = MaterialTheme.shapes.extraLarge
Box(
modifier =
modifier
.clickable { onDish(dish) }
.also {
// this is ignored for now
it
.sharedContainer(
scopes,
dishContainerKey(dish.id),
// resizeMode = ResizeMode.RemeasureToBounds,
resizeMode =
ResizeMode.ScaleToBounds(
contentScale = ContentScale.Crop,
alignment = Alignment.CenterStart,
),
clipInOverlayDuringTransition =
object : OverlayClip {
override fun getClipPath(
sharedContentState: SharedContentState,
bounds: Rect,
layoutDirection: LayoutDirection,
density: Density,
): Path? {
val newRect =
size?.let {
bounds.copy(
left = bounds.center.x - size() / 2f,
right = bounds.center.x + size() / 2f,
)
bounds.copy(
right = bounds.left + size(),
)
} ?: bounds
return OverlayParentClip(shape)
.getClipPath(
sharedContentState,
newRect,
layoutDirection,
modifier
.clickable { onDish(dish) }
.also {
// this is ignored for now
it
.sharedContainer(
scopes,
dishContainerKey(dish.id),
// resizeMode = ResizeMode.RemeasureToBounds,
resizeMode =
ResizeMode.ScaleToBounds(
contentScale = ContentScale.Crop,
alignment = Alignment.CenterStart,
),
clipInOverlayDuringTransition =
object : OverlayClip {
override fun getClipPath(
sharedContentState: SharedContentState,
bounds: Rect,
layoutDirection: LayoutDirection,
density: Density,
): Path? {
val newRect =
size?.let {
bounds.copy(
left = bounds.center.x - size() / 2f,
right = bounds.center.x + size() / 2f,
)
bounds.copy(
right = bounds.left + size(),
)
} ?: bounds
return OverlayParentClip(shape)
.getClipPath(
sharedContentState,
newRect,
layoutDirection,
density,
)
}
},
)
.sharedElement(scopes, key = dishImageKey(dish.id))
).sharedElement(scopes, key = dishImageKey(dish.id))
},
) {
DishImageOrSupplement(
Expand Down

0 comments on commit 8cfda3c

Please sign in to comment.