Merge remote-tracking branch 'origin/main' into step-number-done

# Conflicts:
#	CHANGELOG.md
#	components/src/main/kotlin/de/jeanlucmakiola/floret/components/InstructionSteps.kt
This commit is contained in:
makiolaj committed 2026-10-16 14:49:07 +02:00
commit 29b455341a
35 files changed
+905 -57

No files matched your search

@@ -21,6 +21,6 @@ fun OptionalFormSection(visible: Boolean, content: @Composable ColumnScope.() ->
enter = expandEnter(),
exit = collapseExit(),
) {
Column(modifier = Modifier.fillMaxWidth(), content = content)
Column(modifier = Modifier.fillMaxWidth().revealOnFocus(), content = content)
}
}
@@ -122,7 +122,7 @@ fun GroupedSurface(
position == Position.Top || position == Position.Middle -> Modifier.padding(bottom = 2.dp)
else -> Modifier
}
val base = modifier.fillMaxWidth().then(gap)
val base = modifier.fillMaxWidth().then(gap).revealOnFocus()
val haptics = LocalHapticFeedback.current
when {
onLongClick != null -> Surface(
@@ -159,6 +159,10 @@ fun GroupedSurface(
* the inter-row gap for a caller that owns its own uniform spacing, e.g.
* [ReorderableColumn]. [onLongClick] (see [GroupedSurface]) adds a long-press to
* the row.
*
* [checked] marks a picker row as the chosen one: it implies [selected] and puts
* [SelectedCheck] in the trailing slot when [trailing] is null — the single-select
* picker row without the `if (selected) { { SelectedCheck() } } else null` dance.
*/
@Composable
fun GroupedRow(
@@ -176,6 +180,7 @@ fun GroupedRow(
trailing: @Composable (() -> Unit)? = null,
onClick: (() -> Unit)? = null,
onLongClick: (() -> Unit)? = null,
checked: Boolean = false,
) = GroupedRow(
title = AnnotatedString(title),
position = position,
@@ -191,6 +196,7 @@ fun GroupedRow(
trailing = trailing,
onClick = onClick,
onLongClick = onLongClick,
checked = checked,
)
/**
@@ -215,8 +221,15 @@ fun GroupedRow(
trailing: @Composable (() -> Unit)? = null,
onClick: (() -> Unit)? = null,
onLongClick: (() -> Unit)? = null,
checked: Boolean = false,
) {
val itemColors = if (selected) {
val highlighted = selected || checked
val trailingContent = trailing ?: if (checked) {
{ SelectedCheck() }
} else {
null
}
val itemColors = if (highlighted) {
ListItemDefaults.colors(
containerColor = Color.Transparent,
headlineColor = MaterialTheme.colorScheme.onSecondaryContainer,
@@ -246,7 +259,7 @@ fun GroupedRow(
ListItemDefaults.colors(containerColor = Color.Transparent)
}
val containerColor = when {
selected -> MaterialTheme.colorScheme.secondaryContainer
highlighted -> MaterialTheme.colorScheme.secondaryContainer
container != null -> container
else -> MaterialTheme.colorScheme.surfaceContainerHigh
}
@@ -262,7 +275,7 @@ fun GroupedRow(
headlineContent = { Text(title) },
supportingContent = summary?.let { text -> { Text(text) } },
leadingContent = leading,
trailingContent = trailing,
trailingContent = trailingContent,
colors = itemColors,
modifier = Modifier.heightIn(min = minHeight),
)
@@ -0,0 +1,130 @@
package de.jeanlucmakiola.floret.components
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.KeyboardArrowDown
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import de.jeanlucmakiola.floret.identity.collapseExit
import de.jeanlucmakiola.floret.identity.expandEnter
/**
* A [GroupedRow] with a trailing [Switch], where a tap anywhere on the row flips
* it — the family's settings toggle. [enabled] false dims the row and disables
* both the row and the switch.
*/
@Composable
fun GroupedSwitchRow(
title: String,
checked: Boolean,
onCheckedChange: (Boolean) -> Unit,
position: Position,
modifier: Modifier = Modifier,
summary: String? = null,
enabled: Boolean = true,
leading: @Composable (() -> Unit)? = null,
) {
GroupedRow(
title = title,
position = position,
modifier = modifier,
summary = summary,
dimmed = !enabled,
leading = leading,
trailing = {
Switch(checked = checked, onCheckedChange = onCheckedChange, enabled = enabled)
},
onClick = if (enabled) ({ onCheckedChange(!checked) }) else null,
)
}
/**
* The "Custom…" row that closes a presets-plus-custom picker: a [GroupedRow] that
* toggles [expanded] on tap and reveals [editor] beneath it (typically a
* [CustomAmountEditor]). Expanded, the row takes [Position.Top] so it and the
* editor read as one container; collapsed it sits at [position].
*
* [checked] marks the custom value as the current choice, as on the preset rows;
* the caller names it through [title]/[summary].
*/
@Composable
fun CustomExpandRow(
title: String,
position: Position,
expanded: Boolean,
onExpandedChange: (Boolean) -> Unit,
modifier: Modifier = Modifier,
summary: String? = null,
checked: Boolean = false,
editor: @Composable () -> Unit,
) {
Column(modifier) {
GroupedRow(
title = title,
summary = summary,
position = if (expanded) Position.Top else position,
onClick = { onExpandedChange(!expanded) },
checked = checked,
)
AnimatedVisibility(
visible = expanded,
enter = expandEnter(),
exit = collapseExit(),
) {
editor()
}
}
}
/**
* Muted supporting text outside the cards — under a [GroupedSectionHeader], or
* above a picker's rows — inset to [GroupedListInset] so it shares their edge.
* [style] and [verticalPadding] cover the denser variants (`bodySmall`, 8dp under
* a picker title).
*/
@Composable
fun GroupedHint(
text: String,
modifier: Modifier = Modifier,
style: TextStyle = MaterialTheme.typography.bodyMedium,
verticalPadding: Dp = 4.dp,
) {
Text(
text = text,
style = style,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = modifier.padding(horizontal = GroupedListInset, vertical = verticalPadding),
)
}
/**
* The open/shut chevron for a row that folds content beneath it; turns over as
* [expanded] changes. Decorative — the row carries the semantics.
*/
@Composable
fun ExpandIcon(
expanded: Boolean,
modifier: Modifier = Modifier,
tint: Color = MaterialTheme.colorScheme.onSurfaceVariant,
) {
val turn by animateFloatAsState(if (expanded) 180f else 0f, label = "expand-icon")
Icon(
imageVector = Icons.Rounded.KeyboardArrowDown,
contentDescription = null,
tint = tint,
modifier = modifier.rotate(turn),
)
}
@@ -0,0 +1,83 @@
package de.jeanlucmakiola.floret.components
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
/**
* A free-standing info card: a tonal container with [icon] in a 24dp gutter on
* the left and [content] beside it — a detail screen's "where / when / repeats"
* cards, or the same fields on an edit form.
*
* [onClick] makes the whole card tappable. [iconAlignment] Top with an
* [iconTopPadding] lines the icon up with a multi-line field's first line. A
* tall card passes its first line as [header]: the icon centres on that, and
* [content] continues below it on the same text column.
*/
@Composable
fun IconInfoCard(
icon: ImageVector,
iconContentDescription: String?,
modifier: Modifier = Modifier,
iconTint: Color = MaterialTheme.colorScheme.onSurfaceVariant,
onClick: (() -> Unit)? = null,
iconAlignment: Alignment.Vertical = Alignment.CenterVertically,
iconTopPadding: Dp = 0.dp,
header: (@Composable ColumnScope.() -> Unit)? = null,
content: @Composable ColumnScope.() -> Unit,
) {
val shape = RoundedCornerShape(16.dp)
val color = MaterialTheme.colorScheme.surfaceContainerHigh
val inner: @Composable () -> Unit = {
if (header != null) {
Column(Modifier.padding(16.dp)) {
Row(verticalAlignment = Alignment.CenterVertically) {
CardIcon(icon, iconContentDescription, iconTint, Modifier)
Spacer(Modifier.width(IconGap))
Column(Modifier.weight(1f), content = header)
}
Column(Modifier.padding(start = IconSize + IconGap), content = content)
}
} else {
Row(Modifier.padding(16.dp), verticalAlignment = iconAlignment) {
CardIcon(icon, iconContentDescription, iconTint, Modifier.padding(top = iconTopPadding))
Spacer(Modifier.width(IconGap))
Column(Modifier.weight(1f), content = content)
}
}
}
if (onClick != null) {
Surface(onClick = onClick, color = color, shape = shape, modifier = modifier.fillMaxWidth()) { inner() }
} else {
Surface(color = color, shape = shape, modifier = modifier.fillMaxWidth()) { inner() }
}
}
@Composable
private fun CardIcon(icon: ImageVector, contentDescription: String?, tint: Color, modifier: Modifier) {
Icon(
imageVector = icon,
contentDescription = contentDescription,
tint = tint,
modifier = modifier.size(IconSize),
)
}
private val IconSize = 24.dp
private val IconGap = 16.dp
@@ -91,6 +91,6 @@ fun InlineTextField(
innerTextField()
}
},
modifier = modifier,
modifier = modifier.revealOnFocus(),
)
}
@@ -1,6 +1,5 @@
package de.jeanlucmakiola.floret.components
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
@@ -9,7 +8,6 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Check
import androidx.compose.material.icons.rounded.KeyboardArrowDown
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
@@ -21,7 +19,6 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
@@ -75,7 +72,7 @@ fun InstructionSteps(
minHeight = 56.dp,
// No disc: the empty leading slot is what tells the header
// apart from the numbered rows it opens.
trailing = { Chevron(open) },
trailing = { ExpandIcon(open) },
onClick = { open = !open },
)
}
@@ -153,22 +150,5 @@ fun StepNumber(number: Int, done: Boolean = false) {
}
}
/**
* The open/shut marker.
*
* Decorative: the row it sits on carries the name and the click, so a screen
* reader announcing a chevron as well would be describing the furniture.
*/
@Composable
private fun Chevron(open: Boolean) {
val turn by animateFloatAsState(if (open) 180f else 0f, label = "instruction-chevron")
Icon(
imageVector = Icons.Rounded.KeyboardArrowDown,
contentDescription = null,
tint = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.rotate(turn),
)
}
/** The leading slot's own size, matched to the icons that usually fill it. */
private val StepNumberSize = 28.dp
@@ -19,6 +19,8 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
@@ -30,6 +32,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
@@ -66,6 +69,10 @@ object OnboardingSpace {
* the scrolling content, for a step whose content is taller than the screen: a
* pinned bar there eats the room the content needs and hides the fact that
* there is more of it below.
*
* [headline] and [supporting] are the step's centred title and muted
* explanation, drawn at the top of [body] — the block nearly every step opens
* with. [body] then continues below them, and may be left out entirely.
*/
@Composable
fun OnboardingScaffold(
@@ -77,7 +84,9 @@ fun OnboardingScaffold(
topSpacing: Dp = OnboardingSpace.xl,
contentPadding: Dp = OnboardingSpace.md,
scrollingActions: Boolean = false,
body: @Composable ColumnScope.() -> Unit,
headline: String? = null,
supporting: String? = null,
body: @Composable ColumnScope.() -> Unit = {},
) {
Scaffold(
modifier = modifier,
@@ -120,6 +129,22 @@ fun OnboardingScaffold(
Spacer(Modifier.height(topSpacing))
hero()
Spacer(Modifier.height(OnboardingSpace.lg))
if (headline != null) {
Text(
text = headline,
style = MaterialTheme.typography.headlineMedium,
textAlign = TextAlign.Center,
)
}
if (headline != null && supporting != null) Spacer(Modifier.height(12.dp))
if (supporting != null) {
Text(
text = supporting,
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurfaceVariant,
textAlign = TextAlign.Center,
)
}
body()
// No inset of its own: scrolling actions sit inside the content
// column, so they line up with whatever is above them.
@@ -135,6 +160,37 @@ fun OnboardingScaffold(
}
}
/**
* The step's main call to action for [OnboardingScaffold]'s `actions`: a
* full-width 56dp filled button with a `titleMedium` label, and an optional
* [trailingIcon] (e.g. a forward arrow) after it.
*/
@Composable
fun OnboardingPrimaryButton(
text: String,
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
trailingIcon: ImageVector? = null,
) {
Button(
onClick = onClick,
enabled = enabled,
modifier = modifier.fillMaxWidth().height(56.dp),
contentPadding = if (trailingIcon != null) {
ButtonDefaults.ButtonWithIconContentPadding
} else {
ButtonDefaults.ContentPadding
},
) {
Text(text = text, style = MaterialTheme.typography.titleMedium)
if (trailingIcon != null) {
Spacer(Modifier.width(OnboardingSpace.xs))
Icon(imageVector = trailingIcon, contentDescription = null, modifier = Modifier.size(20.dp))
}
}
}
/** The call-to-action stack, wherever the shell has put it. */
@Composable
private fun ActionsColumn(
@@ -105,6 +105,9 @@ fun FullScreenPicker(
* the cheap middle rung of the richness ladder described on [FullScreenPicker]:
* every option shows its effect at once and stays comparable, without the cost
* of a live preview.
*
* [dismissOnSelect] closes the picker on a pick (the default). Pass false for a
* preview picker, which applies at once and stays open (see [FullScreenPicker]).
*/
@Composable
fun <T> OptionPicker(
@@ -118,28 +121,49 @@ fun <T> OptionPicker(
leading: (@Composable (T) -> Unit)? = null,
header: (@Composable ColumnScope.() -> Unit)? = null,
predictiveBack: Boolean = false,
dismissOnSelect: Boolean = true,
) {
FullScreenPicker(title = title, onDismiss = onDismiss, predictiveBack = predictiveBack) {
header?.invoke(this)
options.forEachIndexed { index, option ->
val isSelected = option == selected
GroupedRow(
title = label(option),
summary = summary?.invoke(option),
position = positionOf(index, options.size),
selected = isSelected,
leading = leading?.let { { it(option) } },
trailing = if (isSelected) {
{ SelectedCheck() }
} else {
null
},
onClick = {
onSelect(option)
onDismiss()
},
)
}
OptionRows(
options = options,
selected = selected,
label = label,
onSelect = {
onSelect(it)
if (dismissOnSelect) onDismiss()
},
summary = summary,
leading = leading,
)
}
}
/**
* [OptionPicker]'s option list on its own: one connected run of [GroupedRow]s,
* the current option highlighted and checked. For a picker that composes its own
* [FullScreenPicker] — a preview above the rows, a description between — but
* wants the standard rows underneath. [onSelect] only reports the pick; closing
* the picker is the caller's call.
*/
@Composable
fun <T> OptionRows(
options: List<T>,
selected: T,
label: @Composable (T) -> String,
onSelect: (T) -> Unit,
summary: (@Composable (T) -> String?)? = null,
leading: (@Composable (T) -> Unit)? = null,
) {
options.forEachIndexed { index, option ->
GroupedRow(
title = label(option),
summary = summary?.invoke(option),
position = positionOf(index, options.size),
leading = leading?.let { { it(option) } },
onClick = { onSelect(option) },
checked = option == selected,
)
}
}
@@ -0,0 +1,62 @@
package de.jeanlucmakiola.floret.components
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.ime
import androidx.compose.foundation.layout.imeAnimationTarget
import androidx.compose.foundation.relocation.BringIntoViewRequester
import androidx.compose.foundation.relocation.bringIntoViewRequester
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.IntSize
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filterNotNull
/**
* Scrolls this whole element into view while anything inside it has focus — once
* the keyboard has finished opening, and again whenever the element resizes.
*
* A text field on its own only brings its text line into view, so a card's
* padding, its label and whatever appears below the field (suggestions, chips)
* stay under the keyboard. [InlineTextField], [GroupedSurface] and
* [OptionalFormSection] apply it already; add it to an app's own card or row
* that holds an input. Needs a scrolling parent whose viewport shrinks with the
* keyboard (`imePadding`).
*
* The keyboard is only read while focused, so an unfocused element never
* recomposes as the keyboard animates.
*/
@OptIn(ExperimentalFoundationApi::class, ExperimentalLayoutApi::class)
fun Modifier.revealOnFocus(): Modifier = composed {
val requester = remember { BringIntoViewRequester() }
var focused by remember { mutableStateOf(false) }
var size by remember { mutableStateOf(IntSize.Zero) }
val density = LocalDensity.current
val ime = WindowInsets.ime
val imeTarget = WindowInsets.imeAnimationTarget
LaunchedEffect(focused) {
if (!focused) return@LaunchedEffect
// Reveal against the final viewport, not one frame of the keyboard sliding in.
snapshotFlow {
val now = ime.getBottom(density)
if (now == imeTarget.getBottom(density)) now to size else null
}
.filterNotNull()
.distinctUntilChanged()
.collect { requester.bringIntoView() }
}
this
.bringIntoViewRequester(requester)
.onSizeChanged { size = it }
.onFocusChanged { focused = it.hasFocus }
}
@@ -5,6 +5,7 @@ import android.net.Uri
import androidx.annotation.XmlRes
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.PaddingValues
@@ -111,7 +112,8 @@ fun AboutCard(
* [AppLanguage]. The choice is mirrored locally so the row updates instantly
* before the activity recreation lands. [autoLabel] names the follow-the-system
* option (the `null` tag); [localesConfig] is the app's `res/xml/locales_config`;
* [leading] is the row's icon.
* [leading] is the row's icon. [header] and [predictiveBack] are forwarded to the
* picker's [OptionPicker] (e.g. a "help translate" row above the languages).
*/
@Composable
fun LanguagePickerRow(
@@ -119,6 +121,8 @@ fun LanguagePickerRow(
title: String,
autoLabel: String,
@XmlRes localesConfig: Int,
header: (@Composable ColumnScope.() -> Unit)? = null,
predictiveBack: Boolean = false,
leading: @Composable () -> Unit,
) {
val context = LocalContext.current
@@ -148,6 +152,8 @@ fun LanguagePickerRow(
AppLanguage.apply(context, it)
},
onDismiss = { showDialog = false },
header = header,
predictiveBack = predictiveBack,
)
}
}