Composables
Docs Login
Pairel

Your Matches Row

Jetpack Compose Component

Download
package com.composables.pairel.components

import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
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.compose.ripple.rememberRippleIndication
import com.composables.pairel.Person
import com.composables.pairel.theme.Theme
import com.composables.uripainter.rememberUriPainter
import kotlin.time.Duration.Companion.milliseconds

@Composable
fun YourMatchesRow(
    people: List<Person>,
    onPersonClick: (Person) -> Unit,
    modifier: Modifier = Modifier,
) {
    LazyRow(
        modifier = modifier.fillMaxWidth(),
        horizontalArrangement = Arrangement.spacedBy(20.dp),
        contentPadding = PaddingValues(horizontal = 20.dp),
    ) {
        items(people, key = { it.name }) { person ->
            MatchTile(person, onClick = { onPersonClick(person) })
        }
    }
}

@Composable
private fun MatchTile(
    person: Person,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
) {
    Column(
        modifier =
            modifier
                .width(100.dp)
                .clip(Theme.shapes.small)
                .clickable(
                    interactionSource = remember { MutableInteractionSource() },
                    indication = rememberRippleIndication(color = Theme.colors.onBackground),
                    onClickLabel = "View ${person.name}'s profile",
                    onClick = onClick,
                )
                .padding(vertical = 8.dp),
        horizontalAlignment = Alignment.CenterHorizontally,
    ) {
        Avatar(
            initials = person.name.take(1),
            contentDescription = "${person.name}'s photo",
            painter =
                rememberUriPainter(
                    person.photoUrl,
                    crossfade = 300.milliseconds,
                    contentScale = ContentScale.Crop,
                ),
            modifier = Modifier.size(76.dp),
        )
        Spacer(Modifier.height(8.dp))
        Text(person.name, style = Theme.typography.label, maxLines = 1)
    }
}

More components from Pairel

by Alex Styl

Search screens and components

Screen flows

Screens

UI Elements