Composables
Docs Login
Pairel

Settings

package com.composables.pairel

import androidx.compose.foundation.background
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.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.WindowInsetsSides
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.union
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
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.unit.dp
import com.composables.compose.ripple.rememberRippleIndication
import com.composables.pairel.components.CenteredAppBar
import com.composables.pairel.components.Icon
import com.composables.pairel.components.IconButton
import com.composables.pairel.components.ScreenScaffold
import com.composables.pairel.components.Separator
import com.composables.pairel.components.SeparatorOrientation
import com.composables.pairel.components.Text
import com.composables.pairel.theme.ArrowLeft
import com.composables.pairel.theme.ChevronRight
import com.composables.pairel.theme.Icons
import com.composables.pairel.theme.Theme

@Composable
fun SettingsScreen(
    navigateBack: () -> Unit,
    navigateToDiscoveryPreferences: () -> Unit,
    navigateToNotifications: () -> Unit,
    navigateToAccountManagement: () -> Unit,
    modifier: Modifier = Modifier,
) {
    ScreenScaffold(
        modifier = modifier,
        topBar = {
            CenteredAppBar(
                title = { Text("Settings") },
                navigation = {
                    IconButton(onClick = navigateBack) {
                        Icon(
                            Icons.ArrowLeft,
                            contentDescription = "Back",
                            modifier = Modifier.size(24.dp),
                        )
                    }
                },
            )
        },
    ) {
        Column(
            Modifier.fillMaxSize()
                .verticalScroll(rememberScrollState())
                .padding(top = 8.dp, bottom = 24.dp)
                .windowInsetsPadding(
                    WindowInsets.navigationBars.union(
                        WindowInsets.safeDrawing.only(WindowInsetsSides.Horizontal)
                    )
                )
                .padding(horizontal = 20.dp),
            horizontalAlignment = Alignment.CenterHorizontally,
        ) {
            Column(
                Modifier.widthIn(max = 560.dp)
                    .fillMaxWidth()
                    .clip(Theme.shapes.large)
                    .background(Theme.colors.surface)
            ) {
                SettingsRow(
                    title = "Discovery preferences",
                    description = "Who you see, their age, and how far away",
                    onClick = navigateToDiscoveryPreferences,
                )
                Separator(SeparatorOrientation.Horizontal, Modifier.padding(horizontal = 20.dp))
                SettingsRow(
                    title = "Notifications",
                    description = "Matches, messages, and likes",
                    onClick = navigateToNotifications,
                )
                Separator(SeparatorOrientation.Horizontal, Modifier.padding(horizontal = 20.dp))
                SettingsRow(
                    title = "Account",
                    description = "Phone number, signing out, and deleting your account",
                    onClick = navigateToAccountManagement,
                )
            }
        }
    }
}

@Composable
private fun SettingsRow(
    title: String,
    description: String,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
) {
    Row(
        modifier =
            modifier
                .fillMaxWidth()
                .clickable(
                    interactionSource = remember { MutableInteractionSource() },
                    indication = rememberRippleIndication(color = Theme.colors.onSurface),
                    onClick = onClick,
                )
                .padding(horizontal = 20.dp, vertical = 16.dp),
        verticalAlignment = Alignment.CenterVertically,
    ) {
        Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(4.dp)) {
            Text(title, style = Theme.typography.label, color = Theme.colors.onSurface)
            Text(description, color = Theme.colors.onBackgroundMuted)
        }
        Spacer(Modifier.width(12.dp))
        Icon(
            Icons.ChevronRight,
            contentDescription = null,
            tint = Theme.colors.onBackgroundMuted,
            modifier = Modifier.size(20.dp),
        )
    }
}

More screens from Pairel

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.