Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions android/app/src/main/java/dev/opencode/mobile/Navigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ import dev.opencode.mobile.ui.componentgallery.components.RenderedMarkdownGaller
import dev.opencode.mobile.ui.componentgallery.components.ReorderableListGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.ReviewChangesPillGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.SectionHeaderGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.OptionCardGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.SelectableCardGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.ServerAddressInputGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.SessionBranchPillGalleryScreen
Expand Down Expand Up @@ -759,6 +760,7 @@ fun MainNavigation() {
ComponentGalleryEntryId.ListItem -> ListItemGalleryScreen()
ComponentGalleryEntryId.SelectableCard ->
SelectableCardGalleryScreen()
ComponentGalleryEntryId.OptionCard -> OptionCardGalleryScreen()
ComponentGalleryEntryId.ListGroup -> ListGroupGalleryScreen()
ComponentGalleryEntryId.SectionHeader -> SectionHeaderGalleryScreen()
ComponentGalleryEntryId.ReorderableList -> ReorderableListGalleryScreen()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ enum class ComponentGalleryEntryId {
Snackbar,
ListItem,
SelectableCard,
OptionCard,
ListGroup,
SectionHeader,
ReorderableList,
Expand Down Expand Up @@ -261,6 +262,12 @@ val ComponentGalleryEntries =
description = "Title, blurb, and preview slot that can be selected.",
category = ComponentGalleryCategory.Lists,
),
ComponentGalleryEntry(
id = ComponentGalleryEntryId.OptionCard,
title = "Option Card",
description = "Bordered single-choice card with radio, title and tag, subtitle, and illustration preview.",
category = ComponentGalleryCategory.Lists,
),
ComponentGalleryEntry(
id = ComponentGalleryEntryId.SectionHeader,
title = "Section Header",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@ private fun ActionSheetEntries(
onClick = onDismiss,
)
}
// Past the 420 compact limit: FitContent rests at half height, FitAllContent shows them all.
if (itemCount >= 12) {
repeat(6) { index ->
OpenCodeBottomSheetEntry(title = "Extra action ${index + 1}", onClick = onDismiss)
}
}
}

@Composable
Expand Down Expand Up @@ -369,7 +375,7 @@ private fun ItemCountControls(
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
Text(text = "Items", style = MaterialTheme.typography.labelLarge, color = MaterialTheme.colorScheme.onSurface)
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
listOf(2, 4, 6).forEach { count ->
listOf(2, 4, 6, 12).forEach { count ->
OpenCodeChoiceBadge(
label = count.toString(),
selected = selected == count,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package dev.opencode.mobile.ui.componentgallery.components

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import dev.opencode.mobile.ui.components.OpenCodeOptionCard
import dev.opencode.mobile.ui.components.OpenCodeOptionCardPreview
import dev.opencode.mobile.ui.components.OpenCodeSkeletonIllustrationTopic
import dev.opencode.mobile.ui.components.OpenCodeTagTone

@Composable
fun OptionCardGalleryScreen(modifier: Modifier = Modifier) {
var selectedIndex by rememberSaveable { mutableIntStateOf(0) }
Column(modifier = modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(16.dp)) {
GallerySectionTitle("Single choice with previews")
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
OpenCodeOptionCard(
title = "Activity Card",
subtitle = "Running steps on one live card that folds into a summary",
tag = "Recommended",
tagTone = OpenCodeTagTone.Accent,
preview = OpenCodeOptionCardPreview.Illustration(OpenCodeSkeletonIllustrationTopic.TimelineActivityCard),
selected = selectedIndex == 0,
onClick = { selectedIndex = 0 },
)
OpenCodeOptionCard(
title = "Standard",
subtitle = "Tool cards and groups between the agent's messages",
tag = "Current",
preview = OpenCodeOptionCardPreview.Illustration(OpenCodeSkeletonIllustrationTopic.TimelineStandard),
selected = selectedIndex == 1,
onClick = { selectedIndex = 1 },
)
OpenCodeOptionCard(
title = "Step Rail",
subtitle = "One line per step on a rail, live while the agent works",
preview = OpenCodeOptionCardPreview.Illustration(OpenCodeSkeletonIllustrationTopic.TimelineStepRail),
selected = selectedIndex == 2,
onClick = { selectedIndex = 2 },
)
}

GallerySectionTitle("Long title: the tag moves under it")
OpenCodeOptionCard(
title = "Activity Card with a longer title",
subtitle = "Running steps on one live card that folds into a summary when the turn ends",
tag = "Recommended",
tagTone = OpenCodeTagTone.Accent,
preview = OpenCodeOptionCardPreview.Illustration(OpenCodeSkeletonIllustrationTopic.TimelineActivityCard),
onClick = {},
)

GallerySectionTitle("Without preview")
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
OpenCodeOptionCard(title = "Title only", selected = true, onClick = {})
OpenCodeOptionCard(title = "With subtitle and tag", subtitle = "A short description", tag = "Beta", onClick = {})
}

GallerySectionTitle("Disabled")
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
OpenCodeOptionCard(
title = "Chips",
subtitle = "Tools as chips under the agent's narration",
preview = OpenCodeOptionCardPreview.Illustration(OpenCodeSkeletonIllustrationTopic.TimelineChips),
enabled = false,
onClick = {},
)
OpenCodeOptionCard(title = "Selected and disabled", selected = true, enabled = false, onClick = {})
}
}
}

@Composable
private fun GallerySectionTitle(title: String) {
Text(text = title, style = MaterialTheme.typography.labelLarge, color = MaterialTheme.colorScheme.onSurface)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import dev.opencode.mobile.ui.components.OpenCodeTag
import dev.opencode.mobile.ui.components.OpenCodeTagSize
import dev.opencode.mobile.ui.components.OpenCodeTagTone

@Composable
fun TagGalleryScreen(modifier: Modifier = Modifier) {
Expand All @@ -25,5 +26,11 @@ fun TagGalleryScreen(modifier: Modifier = Modifier) {
OpenCodeTag(title = "git", size = OpenCodeTagSize.Small)
}
OpenCodeTag(title = "new", size = OpenCodeTagSize.Small)
Text(text = "Accent", style = MaterialTheme.typography.labelLarge, color = MaterialTheme.colorScheme.onSurface)
OpenCodeTag(title = "Recommended", tone = OpenCodeTagTone.Accent)
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp)) {
Text(text = "Activity Card", style = MaterialTheme.typography.bodyLarge)
OpenCodeTag(title = "Recommended", size = OpenCodeTagSize.Small, tone = OpenCodeTagTone.Accent)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ enum class OpenCodeBottomSheetHeight {

/** Fixed at the scrollable half height from the first frame. */
Half,

/**
* Like [FitContent], but wraps all content up to the tallest sheet the window allows (the
* window less the top inset and the top gap, the same top limit an expanded sheet uses).
* Only content taller than that scrolls, and the sheet then rests at that maximum, not at
* half height. For short choice lists that must show every option at once.
*/
FitAllContent,
}

/** How an [OpenCodeBottomSheet] treats the software keyboard. */
Expand Down Expand Up @@ -464,6 +472,7 @@ fun OpenCodeBottomSheet(
scrollTargetKey = shown.scrollTargetKey,
threeButtonNavigation = threeButtonNav,
windowHeight = maxHeight,
sheetBottomInset = sheetBottomInset,
onDismissRequest = requestDismiss,
headerDragModifier =
Modifier.draggable(
Expand Down Expand Up @@ -626,14 +635,25 @@ private fun BottomSheetContent(
scrollTargetKey: Any?,
threeButtonNavigation: Boolean,
windowHeight: Dp,
sheetBottomInset: Dp,
onDismissRequest: () -> Unit,
headerDragModifier: Modifier,
pinnedTop: @Composable ColumnScope.() -> Unit,
pinnedBottom: (@Composable ColumnScope.() -> Unit)?,
content: @Composable ColumnScope.() -> Unit,
) {
val density = LocalDensity.current
val maxSheetHeight = openCodeBottomSheetHalfHeight(windowHeight)
val fitsAllContent = height == OpenCodeBottomSheetHeight.FitAllContent
val windowTopInset =
WindowInsets.systemBars
.union(WindowInsets.displayCutout)
.asPaddingValues()
.calculateTopPadding()
val fitAllMaxHeight = openCodeBottomSheetFitAllMaxHeight(windowHeight, windowTopInset, sheetBottomInset)
// Column height (inside its bottom padding) once scrollable, and the compact limit it must pass.
val maxSheetHeight =
if (fitsAllContent) fitAllMaxHeight - BottomSheetContentBottomPadding else openCodeBottomSheetHalfHeight(windowHeight)
val compactMaxHeight = if (fitsAllContent) fitAllMaxHeight else BottomSheetCompactMaxHeight
var contentHeight by remember { mutableStateOf(0.dp) }
var headerHeight by remember { mutableStateOf(0.dp) }
var pinnedTopHeight by remember { mutableStateOf(0.dp) }
Expand All @@ -653,14 +673,15 @@ private fun BottomSheetContent(
}

val layoutMode =
remember(height, committedToScrollable, contentHeight, headerHeight, pinnedTopHeight, pinnedBottomHeight) {
remember(height, committedToScrollable, contentHeight, headerHeight, pinnedTopHeight, pinnedBottomHeight, compactMaxHeight) {
openCodeBottomSheetLayoutMode(
height = height,
committedToScrollable = committedToScrollable,
headerHeight = headerHeight,
pinnedTopHeight = pinnedTopHeight,
contentHeight = contentHeight,
pinnedBottomHeight = pinnedBottomHeight,
compactMaxHeight = compactMaxHeight,
)
}

Expand Down Expand Up @@ -724,7 +745,7 @@ private fun BottomSheetContent(
Modifier.bottomSheetFixedHeight(keyboardSheetHeight)
} else {
Modifier
.heightIn(max = BottomSheetCompactMaxHeight)
.heightIn(max = if (fitsAllContent) maxSheetHeight else BottomSheetCompactMaxHeight)
.wrapContentHeight()
}
BottomSheetLayoutMode.Measuring -> Modifier.heightIn(max = maxSheetHeight)
Expand Down Expand Up @@ -900,6 +921,19 @@ private fun BottomSheetHeader(
/** Scrollable half height: half the window, less the gap above the sheet. */
internal fun openCodeBottomSheetHalfHeight(windowHeight: Dp): Dp = windowHeight * BottomSheetScrollableHeightFraction - BottomSheetInset

/**
* Tallest [OpenCodeBottomSheetHeight.FitAllContent] sheet, its column plus bottom padding: the
* window less the top system inset, the top gap, and the sheet's bottom inset. Never shorter
* than a half-height sheet, so a cramped window still scrolls at half height.
*/
internal fun openCodeBottomSheetFitAllMaxHeight(
windowHeight: Dp,
topInset: Dp,
bottomInset: Dp,
): Dp =
(windowHeight - topInset - BottomSheetInset - bottomInset)
.coerceAtLeast(openCodeBottomSheetHalfHeight(windowHeight) + BottomSheetContentBottomPadding)

/** The measured header height, or an estimate before the header has laid out. */
internal fun openCodeBottomSheetResolvedHeaderHeight(headerHeight: Dp): Dp =
if (headerHeight > 0.dp) headerHeight else BottomSheetEstimatedHeaderHeight
Expand All @@ -913,9 +947,10 @@ internal fun openCodeBottomSheetMeasuredHeight(
): Dp = openCodeBottomSheetResolvedHeaderHeight(headerHeight) + pinnedTopHeight + contentHeight + pinnedBottomHeight

/**
* Layout for a sheet of [height]. [OpenCodeBottomSheetHeight.Half] and a FitContent sheet that
* already reached half height are scrollable; otherwise FitContent stays compact while the
* measured column and bottom padding fit [BottomSheetCompactMaxHeight].
* Layout for a sheet of [height]. [OpenCodeBottomSheetHeight.Half] and a fitting sheet that
* already turned scrollable are scrollable; otherwise a fitting sheet stays compact while the
* measured column and bottom padding fit [compactMaxHeight]: [BottomSheetCompactMaxHeight] for
* FitContent, [openCodeBottomSheetFitAllMaxHeight] for FitAllContent.
*/
internal fun openCodeBottomSheetLayoutMode(
height: OpenCodeBottomSheetHeight,
Expand All @@ -924,13 +959,14 @@ internal fun openCodeBottomSheetLayoutMode(
pinnedTopHeight: Dp,
contentHeight: Dp,
pinnedBottomHeight: Dp,
compactMaxHeight: Dp = BottomSheetCompactMaxHeight,
): BottomSheetLayoutMode {
if (height == OpenCodeBottomSheetHeight.Half || committedToScrollable) return BottomSheetLayoutMode.Scrollable
if (contentHeight == 0.dp) return BottomSheetLayoutMode.Measuring
val total =
openCodeBottomSheetMeasuredHeight(headerHeight, pinnedTopHeight, contentHeight, pinnedBottomHeight) +
BottomSheetContentBottomPadding
return if (total > BottomSheetCompactMaxHeight) BottomSheetLayoutMode.Scrollable else BottomSheetLayoutMode.Compact
return if (total > compactMaxHeight) BottomSheetLayoutMode.Scrollable else BottomSheetLayoutMode.Compact
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import androidx.compose.ui.unit.dp
import dev.opencode.mobile.theme.OpenCodePillShape
import dev.opencode.mobile.theme.openCodeColor

/** Fill opacity of the interactive color behind an [OpenCodeTagTone.Accent] tag. */
internal const val OPEN_CODE_TAG_ACCENT_FILL_ALPHA = 0.12f

enum class OpenCodeTagSize {
/** Standalone label, such as the onboarding "Unofficial" tag. */
Regular,
Expand All @@ -19,20 +22,41 @@ enum class OpenCodeTagSize {
Small,
}

/** Color treatment of an [OpenCodeTag]. */
enum class OpenCodeTagTone {
/** Quiet gray label; the default. */
Neutral,

/** Interactive-tinted label that draws the eye, such as a "Recommended" choice. */
Accent,
}

/** Static capsule label. */
@Composable
fun OpenCodeTag(
title: String,
modifier: Modifier = Modifier,
size: OpenCodeTagSize = OpenCodeTagSize.Regular,
tone: OpenCodeTagTone = OpenCodeTagTone.Neutral,
) {
require(title.isNotBlank()) { "Tag requires a non-blank title" }
val accentFill = openCodeColor("interactive").copy(alpha = OPEN_CODE_TAG_ACCENT_FILL_ALPHA)
val accentText = openCodeColor("text-interactive-base")
when (size) {
OpenCodeTagSize.Regular ->
Surface(
modifier = modifier,
shape = OpenCodePillShape,
color = MaterialTheme.colorScheme.surfaceVariant,
color =
when (tone) {
OpenCodeTagTone.Neutral -> MaterialTheme.colorScheme.surfaceVariant
OpenCodeTagTone.Accent -> accentFill
},
contentColor =
when (tone) {
OpenCodeTagTone.Neutral -> MaterialTheme.colorScheme.onSurfaceVariant
OpenCodeTagTone.Accent -> accentText
},
) {
Text(
text = title,
Expand All @@ -44,8 +68,16 @@ fun OpenCodeTag(
Surface(
modifier = modifier,
shape = OpenCodePillShape,
color = openCodeColor("surface-raised-base"),
contentColor = openCodeColor("text-weak"),
color =
when (tone) {
OpenCodeTagTone.Neutral -> openCodeColor("surface-raised-base")
OpenCodeTagTone.Accent -> accentFill
},
contentColor =
when (tone) {
OpenCodeTagTone.Neutral -> openCodeColor("text-weak")
OpenCodeTagTone.Accent -> accentText
},
) {
Text(
text = title,
Expand Down
Loading
Loading