found a place where image gallery was used for single images

This commit is contained in:
davotoula
2025-09-12 12:14:05 +02:00
parent ee9e102eb2
commit 16e3cba651

View File

@@ -404,10 +404,9 @@ private fun RenderSingleParagraphWithFlowRow(
FlowRow( FlowRow(
horizontalArrangement = Arrangement.spacedBy(spaceWidth), horizontalArrangement = Arrangement.spacedBy(spaceWidth),
) { ) {
RenderWordsWithImageGallery( words.forEach { word ->
words, RenderWordWithPreview(word, context)
context, }
)
} }
} }
} }
@@ -797,7 +796,7 @@ fun CoreSecretMessage(
) )
if (localSecretContent.paragraphs.size == 1) { if (localSecretContent.paragraphs.size == 1) {
RenderWordsWithImageGallery( RenderSecretParagraphOptimized(
localSecretContent.paragraphs[0].words.toImmutableList(), localSecretContent.paragraphs[0].words.toImmutableList(),
context, context,
) )
@@ -806,18 +805,48 @@ fun CoreSecretMessage(
Column(CashuCardBorders) { Column(CashuCardBorders) {
localSecretContent.paragraphs.forEach { paragraph -> localSecretContent.paragraphs.forEach { paragraph ->
FlowRow( RenderSecretParagraphOptimized(
modifier = Modifier.align(if (paragraph.isRTL) Alignment.End else Alignment.Start),
horizontalArrangement = Arrangement.spacedBy(spaceWidth),
) {
RenderWordsWithImageGallery(
paragraph.words.toImmutableList(), paragraph.words.toImmutableList(),
context, context,
spaceWidth,
paragraph.isRTL,
) )
} }
} }
} }
} }
@OptIn(ExperimentalLayoutApi::class)
@Composable
private fun RenderSecretParagraphOptimized(
words: ImmutableList<Segment>,
context: RenderContext,
spaceWidth: Dp? = null,
isRTL: Boolean = false,
) {
// Check if we need single-image optimization
val imageSegments = words.filter { it is ImageSegment || it is Base64Segment }
if (imageSegments.size > 1) {
// Multiple images - use gallery logic
RenderWordsWithImageGallery(words, context)
} else {
// Single or no images - render directly with FlowRow for optimal performance
val actualSpaceWidth = spaceWidth ?: measureSpaceWidth(LocalTextStyle.current)
CompositionLocalProvider(
LocalLayoutDirection provides if (isRTL) LayoutDirection.Rtl else LayoutDirection.Ltr,
LocalTextStyle provides LocalTextStyle.current,
) {
FlowRow(
horizontalArrangement = Arrangement.spacedBy(actualSpaceWidth),
) {
words.forEach { word ->
RenderWordWithPreview(word, context)
}
}
}
}
} }
@Composable @Composable