From 0e6f970e889b3085fadb7a9be189af86e078a22d Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 5 Apr 2026 14:25:28 +0000 Subject: [PATCH] feat: add @Preview for NoteComposeLayout Add two previews: full layout with all slots (author picture, relay badges, header rows, content, reactions) and a boosted variant without author column or padding. https://claude.ai/code/session_01Fam5VHNaNkKBBafg1gRfFS --- .../amethyst/ui/layouts/NoteComposeLayout.kt | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/layouts/NoteComposeLayout.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/layouts/NoteComposeLayout.kt index 58c50927f..21b6ac776 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/layouts/NoteComposeLayout.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/layouts/NoteComposeLayout.kt @@ -20,16 +20,29 @@ */ package com.vitorpamplona.amethyst.ui.layouts +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.Immutable import androidx.compose.runtime.remember import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.Layout import androidx.compose.ui.layout.Placeable import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.Constraints import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp import com.vitorpamplona.amethyst.ui.theme.Size55dp +import com.vitorpamplona.amethyst.ui.theme.ThemeComparisonColumn private val ZeroConstraints = Constraints.fixed(0, 0) @@ -44,6 +57,82 @@ private data class NoteLayoutPx( val padTop: Int, ) +@Composable +@Preview +private fun NoteComposeLayoutPreview() { + ThemeComparisonColumn { + NoteComposeLayoutPreviewCard() + } +} + +@Composable +private fun NoteComposeLayoutPreviewCard() { + NoteComposeLayout( + modifier = Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.surface), + showSecondRow = true, + authorPicture = { + Box( + Modifier + .size(55.dp) + .clip(CircleShape) + .background(Color(0xFF9575CD)), + ) + }, + relayBadges = { + Text("R1 R2 R3", fontSize = 10.sp, color = Color.Gray) + }, + firstRow = { + Text( + "Alice @alice 2h ...", + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + }, + secondRow = { + Text( + "alice@nostr.com", + fontSize = 12.sp, + color = Color.Gray, + maxLines = 1, + ) + }, + noteContent = { + Text( + "This is a sample note content that demonstrates the custom " + + "NoteComposeLayout with all slots populated. The layout handles " + + "author picture, relay badges, header rows, content, and reactions.", + ) + }, + reactionsRow = { + Text(" Reply 3 Boost 5 Like 12 Zap 1.2k", fontSize = 12.sp, color = Color.Gray) + }, + ) +} + +@Composable +@Preview +private fun NoteComposeLayoutBoostedPreview() { + ThemeComparisonColumn { + NoteComposeLayout( + modifier = Modifier.fillMaxWidth().background(MaterialTheme.colorScheme.surface), + addPadding = false, + showAuthorColumn = false, + authorPicture = {}, + relayBadges = {}, + firstRow = { + Text("Bob boosted 2h ...") + }, + secondRow = {}, + noteContent = { + Text("Boosted note content without author column or padding.") + }, + reactionsRow = { + Text(" Reply Boost Like Zap", fontSize = 12.sp, color = Color.Gray) + }, + ) + } +} + /** * Custom zero-overhead layout for note items. Uses the multi-content [Layout] * overload to eliminate ALL intermediate wrapper nodes (Box/Column). Each slot's