Composables
Docs Login
Vela

Attachment Chip

Jetpack Compose Component

Download
package com.composables.vela.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
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.Icons
import com.composables.vela.theme.Theme
import com.composables.vela.theme.X
import kotlin.time.Duration.Companion.milliseconds

@Composable
fun AttachmentChip(
    imageUri: String,
    contentDescription: String,
    onRemove: () -> Unit,
    modifier: Modifier = Modifier,
) {
    Box(modifier.padding(top = 6.dp, end = 6.dp)) {
        Image(
            painter =
                rememberUriPainter(
                    imageUri,
                    crossfade = 300.milliseconds,
                    contentScale = ContentScale.Crop,
                ),
            contentDescription = contentDescription,
            contentScale = ContentScale.Crop,
            modifier =
                Modifier.size(56.dp)
                    .clip(Theme.shapes.small)
                    .background(Theme.colors.surfaceVariant),
        )
        IconButton(
            onClick = onRemove,
            contentDescription = "Remove $contentDescription",
            variant = IconButtonVariant.Tonal,
            size = IconButtonSize.Small,
            modifier = Modifier.align(Alignment.TopEnd).offset(x = 10.dp, y = (-10).dp).size(24.dp),
        ) {
            Icon(Icons.X, contentDescription = null, modifier = Modifier.size(12.dp))
        }
    }
}

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.