Composables
Docs Login
Vela

Choice Tile

Jetpack Compose Component

Download
package com.composables.vela.components

import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.selection.selectable
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.dp
import com.composables.compose.ripple.rememberRippleIndication
import com.composables.vela.theme.Space
import com.composables.vela.theme.Theme

@Composable
fun ChoiceTile(
    selected: Boolean,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
    contentPadding: PaddingValues = PaddingValues(Space * 3),
    content: @Composable ColumnScope.() -> Unit,
) {
    val outline by
        animateColorAsState(
            if (selected) Theme.colors.primary else Theme.colors.border,
            tween(160),
            label = "Outline",
        )
    Column(
        modifier
            .clip(Theme.shapes.small)
            .background(if (selected) Theme.colors.surfaceVariant else Theme.colors.surface)
            .border(if (selected) 2.dp else 1.dp, outline, Theme.shapes.small)
            .selectable(
                selected = selected,
                onClick = onClick,
                role = Role.RadioButton,
                interactionSource = remember { MutableInteractionSource() },
                indication = rememberRippleIndication(color = Theme.colors.onSurface),
            )
            .padding(contentPadding),
        verticalArrangement = Arrangement.spacedBy(Space),
        content = content,
    )
}

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.