|
| 1 | +package com.flipcash.app.messenger.internal.screens.components |
| 2 | + |
| 3 | +import androidx.compose.foundation.layout.Arrangement |
| 4 | +import androidx.compose.foundation.layout.Box |
| 5 | +import androidx.compose.foundation.layout.Column |
| 6 | +import androidx.compose.foundation.layout.Row |
| 7 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 8 | +import androidx.compose.foundation.layout.height |
| 9 | +import androidx.compose.foundation.layout.padding |
| 10 | +import androidx.compose.foundation.layout.size |
| 11 | +import androidx.compose.foundation.layout.widthIn |
| 12 | +import androidx.compose.material.icons.Icons |
| 13 | +import androidx.compose.material.icons.outlined.Info |
| 14 | +import androidx.compose.material3.Icon |
| 15 | +import androidx.compose.material3.Text |
| 16 | +import androidx.compose.runtime.Composable |
| 17 | +import androidx.compose.ui.Alignment |
| 18 | +import androidx.compose.ui.Modifier |
| 19 | +import androidx.compose.ui.platform.LocalDensity |
| 20 | +import androidx.compose.ui.semantics.semantics |
| 21 | +import androidx.compose.ui.text.style.TextAlign |
| 22 | +import androidx.compose.ui.tooling.preview.Preview |
| 23 | +import androidx.compose.ui.tooling.preview.PreviewWrapper |
| 24 | +import androidx.compose.ui.unit.dp |
| 25 | +import com.flipcash.app.theme.FlipcashThemeWrapper |
| 26 | +import com.getcode.theme.CodeTheme |
| 27 | + |
| 28 | +/** |
| 29 | + * A server notice, centred in the transcript (node 11721:879, option D, file Jxf2wD9QyfKaONbhHSdU0K): |
| 30 | + * an info glyph, then the text. No fill, no bubble and no sender label. The glyph is what tells it |
| 31 | + * apart from the date separator, which is also centred caption text. |
| 32 | + * |
| 33 | + * The text is drawn as it arrived: it wraps at [SYSTEM_TEXT_MAX_WIDTH], centred, with no `maxLines` |
| 34 | + * and no trimming. The glyph stays beside the first line. |
| 35 | + */ |
| 36 | +@Composable |
| 37 | +internal fun SystemMessageRow(text: String, modifier: Modifier = Modifier) { |
| 38 | + val lineHeight = with(LocalDensity.current) { CodeTheme.typography.caption.lineHeight.toDp() } |
| 39 | + |
| 40 | + Row( |
| 41 | + modifier = modifier |
| 42 | + .fillMaxWidth() |
| 43 | + .padding(vertical = SYSTEM_ROW_VERTICAL_PADDING) |
| 44 | + .semantics(mergeDescendants = true) {}, |
| 45 | + verticalAlignment = Alignment.Top, |
| 46 | + horizontalArrangement = Arrangement.spacedBy(SYSTEM_GLYPH_GAP, Alignment.CenterHorizontally), |
| 47 | + ) { |
| 48 | + // One line tall, so the glyph centres on the first line however many the text wraps to. |
| 49 | + Box(modifier = Modifier.height(lineHeight), contentAlignment = Alignment.Center) { |
| 50 | + Icon( |
| 51 | + modifier = Modifier.size(SYSTEM_GLYPH_SIZE), |
| 52 | + imageVector = Icons.Outlined.Info, |
| 53 | + contentDescription = null, |
| 54 | + tint = CodeTheme.colors.textSecondary, |
| 55 | + ) |
| 56 | + } |
| 57 | + Text( |
| 58 | + modifier = Modifier.widthIn(max = SYSTEM_TEXT_MAX_WIDTH), |
| 59 | + text = text, |
| 60 | + style = CodeTheme.typography.caption, |
| 61 | + color = CodeTheme.colors.textSecondary, |
| 62 | + textAlign = TextAlign.Center, |
| 63 | + ) |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +private val SYSTEM_GLYPH_SIZE = 14.dp |
| 68 | +private val SYSTEM_GLYPH_GAP = 6.dp |
| 69 | +private val SYSTEM_TEXT_MAX_WIDTH = 250.dp |
| 70 | +private val SYSTEM_ROW_VERTICAL_PADDING = 6.dp |
| 71 | + |
| 72 | +@Preview |
| 73 | +@PreviewWrapper(FlipcashThemeWrapper::class) |
| 74 | +@Composable |
| 75 | +private fun Preview_SystemMessageRow() { |
| 76 | + Column(modifier = Modifier.padding(horizontal = CodeTheme.dimens.inset)) { |
| 77 | + SystemMessageRow("Alex joined the group") |
| 78 | + SystemMessageRow("Alex added Sam, Jordan and Riley to the group, and changed the group name to Weekend plans") |
| 79 | + } |
| 80 | +} |
0 commit comments