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 @@ -40,6 +40,7 @@ import dev.opencode.mobile.ui.componentgallery.components.AttachmentGalleryScree
import dev.opencode.mobile.ui.componentgallery.components.BottomSheetGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.ButtonGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.ChoiceBadgeGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.FilterTabsGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.DialogGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.SnackbarGalleryScreen
import dev.opencode.mobile.ui.componentgallery.components.HunkNavigationPillGalleryScreen
Expand Down Expand Up @@ -187,6 +188,7 @@ fun MainNavigation() {
ComponentGalleryEntryId.ListItem -> ListItemGalleryScreen()
ComponentGalleryEntryId.ListGroup -> ListGroupGalleryScreen()
ComponentGalleryEntryId.ChoiceBadge -> ChoiceBadgeGalleryScreen()
ComponentGalleryEntryId.FilterTabs -> FilterTabsGalleryScreen()
ComponentGalleryEntryId.ActionPill -> ActionPillGalleryScreen()
ComponentGalleryEntryId.ComposerSuggestionOverlay ->
ComposerSuggestionOverlayGalleryScreen()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum class ComponentGalleryEntryId {
ListItem,
ListGroup,
ChoiceBadge,
FilterTabs,
ActionPill,
ComposerSuggestionOverlay,
ReviewChangesPill,
Expand Down Expand Up @@ -96,6 +97,12 @@ val ComponentGalleryEntries =
description = "Selectable pill for compact single-choice controls.",
category = ComponentGalleryCategory.Controls,
),
ComponentGalleryEntry(
id = ComponentGalleryEntryId.FilterTabs,
title = "Filter Tabs",
description = "Horizontal single-select filters with optional count badges.",
category = ComponentGalleryCategory.Controls,
),
ComponentGalleryEntry(
id = ComponentGalleryEntryId.TextInput,
title = "Text Input",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package dev.opencode.mobile.ui.componentgallery.components

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
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.OpenCodeFilterTab
import dev.opencode.mobile.ui.components.OpenCodeFilterTabs

@Composable
fun FilterTabsGalleryScreen(modifier: Modifier = Modifier) {
var selectedTabId by rememberSaveable { mutableStateOf("all") }
Column(modifier = modifier.fillMaxSize()) {
Text(
text = "Horizontal single-select filters with optional count badges.",
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
)
OpenCodeFilterTabs(
tabs = filterTabsGallerySamples,
selectedTabId = selectedTabId,
onTabSelected = { selectedTabId = it },
)
}
}

private val filterTabsGallerySamples =
listOf(
OpenCodeFilterTab(id = "all", title = "All", count = 5),
OpenCodeFilterTab(id = "friends", title = "Friends"),
OpenCodeFilterTab(id = "unread", title = "Unread", count = 45),
OpenCodeFilterTab(id = "news", title = "News", count = 10),
OpenCodeFilterTab(id = "mobile", title = "opencode-mobile", count = 3),
)
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
package dev.opencode.mobile.ui.componentgallery.components

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import dev.opencode.mobile.theme.LetterAccent
import dev.opencode.mobile.ui.components.SessionList
import dev.opencode.mobile.ui.components.SessionListFilterTab
import dev.opencode.mobile.ui.components.SessionListSession
import dev.opencode.mobile.ui.components.SessionListStatus

@Composable
fun SessionListGalleryScreen(modifier: Modifier = Modifier) {
var selectedFilterId by rememberSaveable { mutableStateOf(SessionListFilterTab.ALL_ID) }
SessionList(
sessions = sessionListGallerySamples,
filterTabs = sessionListGalleryFilterTabs,
selectedFilterId = selectedFilterId,
onFilterSelected = { selectedFilterId = it },
onSessionSelected = {},
onAddProject = {},
onNewSession = {},
modifier = modifier,
)
}
Expand Down Expand Up @@ -59,3 +70,15 @@ private val sessionListGallerySamples =
caption = "2d ago",
),
)

private val sessionListGalleryFilterTabs =
listOf(
SessionListFilterTab(id = SessionListFilterTab.ALL_ID, title = "All", count = 4),
SessionListFilterTab(
id = "/Users/demo/opencode-mobile",
title = "opencode-mobile",
count = 2,
),
SessionListFilterTab(id = "/Users/demo/playground", title = "playground", count = 1),
SessionListFilterTab(id = "/Users/demo/api-client", title = "api-client", count = 1),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
package dev.opencode.mobile.ui.components

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.selected
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.PlatformTextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.LineHeightStyle
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import dev.opencode.mobile.theme.OpenCodeTheme

private val FilterTabsTabShape = RoundedCornerShape(percent = 50)
private val FilterTabsCountShape = RoundedCornerShape(percent = 50)
private val FilterTabsTabPaddingHorizontal = 12.dp
private val FilterTabsTabPaddingVertical = 8.dp
private val FilterTabsTabMinHeight = 36.dp
private val FilterTabsTabSpacing = 8.dp
private val FilterTabsContentSpacing = 6.dp
private val FilterTabsCountSize = 22.dp
private val FilterTabsCountPaddingHorizontal = 6.dp
private val FilterTabsRowPaddingHorizontal = 16.dp
private val FilterTabsRowPaddingVertical = 8.dp
private val FilterTabsBorderWidth = 1.5.dp

data class OpenCodeFilterTab(
val id: String,
val title: String,
val count: Int? = null,
)

@Composable
fun OpenCodeFilterTabs(
tabs: List<OpenCodeFilterTab>,
selectedTabId: String,
onTabSelected: (String) -> Unit,
modifier: Modifier = Modifier,
) {
if (tabs.isEmpty()) return
Row(
modifier =
modifier
.fillMaxWidth()
.horizontalScroll(rememberScrollState())
.padding(
horizontal = FilterTabsRowPaddingHorizontal,
vertical = FilterTabsRowPaddingVertical,
),
horizontalArrangement = Arrangement.spacedBy(FilterTabsTabSpacing),
verticalAlignment = Alignment.CenterVertically,
) {
tabs.forEach { tab ->
FilterTabItem(
tab = tab,
selected = tab.id == selectedTabId,
onClick = { onTabSelected(tab.id) },
)
}
}
}

@Composable
private fun FilterTabItem(
tab: OpenCodeFilterTab,
selected: Boolean,
onClick: () -> Unit,
) {
val labelColor =
if (selected) {
MaterialTheme.colorScheme.onSurface
} else {
MaterialTheme.colorScheme.onSurfaceVariant
}
val border =
if (selected) {
BorderStroke(FilterTabsBorderWidth, MaterialTheme.colorScheme.outline)
} else {
null
}
val accessibilityLabel =
tab.count?.let { "${tab.title}, $it" } ?: tab.title

Surface(
onClick = onClick,
modifier =
Modifier
.heightIn(min = FilterTabsTabMinHeight)
.semantics {
this.selected = selected
contentDescription = accessibilityLabel
},
shape = FilterTabsTabShape,
color = Color.Transparent,
border = border,
) {
Row(
modifier =
Modifier.padding(
horizontal = FilterTabsTabPaddingHorizontal,
vertical = FilterTabsTabPaddingVertical,
),
horizontalArrangement = Arrangement.spacedBy(FilterTabsContentSpacing),
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = tab.title,
style = MaterialTheme.typography.labelMedium,
color = labelColor,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
tab.count?.let { count ->
Box(
modifier =
Modifier
.height(FilterTabsCountSize)
.widthIn(min = FilterTabsCountSize)
.clip(FilterTabsCountShape)
.background(MaterialTheme.colorScheme.surfaceVariant)
.padding(horizontal = FilterTabsCountPaddingHorizontal),
contentAlignment = Alignment.Center,
) {
Text(
text = count.toString(),
color = MaterialTheme.colorScheme.onSurfaceVariant,
style =
MaterialTheme.typography.labelSmall.copy(
fontWeight = FontWeight.SemiBold,
platformStyle = PlatformTextStyle(includeFontPadding = false),
lineHeightStyle =
LineHeightStyle(
alignment = LineHeightStyle.Alignment.Center,
trim = LineHeightStyle.Trim.Both,
),
),
maxLines = 1,
)
}
}
}
}
}

@Preview(showBackground = true)
@Composable
private fun OpenCodeFilterTabsPreview() {
OpenCodeTheme(darkTheme = true) {
OpenCodeFilterTabs(
tabs =
listOf(
OpenCodeFilterTab(id = "all", title = "All", count = 5),
OpenCodeFilterTab(id = "friends", title = "Friends"),
OpenCodeFilterTab(id = "unread", title = "Unread", count = 45),
OpenCodeFilterTab(id = "news", title = "News", count = 10),
),
selectedTabId = "all",
onTabSelected = {},
)
}
}
Loading
Loading