Composables
Docs Login
Vela

User Message

Jetpack Compose Component

Download
package com.composables.vela.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.widthIn
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import com.composables.uripainter.rememberUriPainter
import com.composables.vela.theme.Space
import com.composables.vela.theme.Theme
import kotlin.time.Duration.Companion.milliseconds

@Composable
fun UserMessage(
    text: String,
    modifier: Modifier = Modifier,
    imageUris: List<String> = emptyList(),
) {
    Column(
        modifier.fillMaxWidth(),
        horizontalAlignment = Alignment.End,
        verticalArrangement = Arrangement.spacedBy(Space * 2),
    ) {
        if (imageUris.isNotEmpty()) {
            Row(horizontalArrangement = Arrangement.spacedBy(Space * 2)) {
                imageUris.forEach { uri ->
                    Image(
                        painter =
                            rememberUriPainter(
                                uri,
                                crossfade = 300.milliseconds,
                                contentScale = ContentScale.Crop,
                            ),
                        contentDescription = "Attached photo",
                        contentScale = ContentScale.Crop,
                        modifier =
                            Modifier.size(96.dp)
                                .clip(Theme.shapes.medium)
                                .background(Theme.colors.surfaceVariant),
                    )
                }
            }
        }
        if (text.isNotEmpty()) {
            Text(
                text,
                color = Theme.colors.onSurface,
                modifier =
                    Modifier.widthIn(max = 300.dp)
                        .clip(Theme.shapes.medium)
                        .background(Theme.colors.surface)
                        .padding(horizontal = Space * 4, vertical = Space * 2.5f),
            )
        }
    }
}

More components from Vela

by Alex Styl

Search screens and components

Screen flows

Screens

UI Elements

One Android lesson, every Wednesday

Building Android apps?

What Alex learned building Android apps for 14 years, so you don't have to. Reads in under a minute.

Join 3,500+ Android developers. Unsubscribe any time.

You're subscribed

The next lesson lands in on Wednesday.