主页换 Flexible 大标题,空状态与令牌图标采用 Expressive 形状底座
This commit is contained in:
@@ -31,7 +31,9 @@ import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.focus.onFocusChanged
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -45,9 +47,10 @@ import cn.airnan.a2fair.R
|
||||
import cn.airnan.a2fair.data.entity.Group
|
||||
import cn.airnan.a2fair.data.entity.Token
|
||||
import cn.airnan.a2fair.data.entity.TokenType
|
||||
import kotlin.math.abs
|
||||
import kotlinx.coroutines.delay
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalMaterial3ExpressiveApi::class)
|
||||
@Composable
|
||||
fun TokensScreen(
|
||||
viewModel: TokensViewModel,
|
||||
@@ -59,6 +62,7 @@ fun TokensScreen(
|
||||
var searchFieldHasFocus by remember { mutableStateOf(false) }
|
||||
val searchFocusRequester = remember { FocusRequester() }
|
||||
val focusManager = LocalFocusManager.current
|
||||
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
|
||||
|
||||
LaunchedEffect(isSearchExpanded) {
|
||||
if (isSearchExpanded) {
|
||||
@@ -67,26 +71,17 @@ fun TokensScreen(
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
|
||||
topBar = {
|
||||
if (isSearchExpanded) {
|
||||
TopAppBar(
|
||||
title = {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
AnimatedVisibility(visible = !isSearchExpanded) {
|
||||
Text(stringResource(R.string.tokens))
|
||||
}
|
||||
AnimatedVisibility(
|
||||
visible = isSearchExpanded,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(end = 16.dp)
|
||||
) {
|
||||
Surface(
|
||||
shape = MaterialTheme.shapes.large,
|
||||
color = MaterialTheme.colorScheme.surfaceContainerHighest,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(end = 16.dp)
|
||||
) {
|
||||
TextField(
|
||||
value = uiState.searchQuery,
|
||||
@@ -119,16 +114,18 @@ fun TokensScreen(
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
} else {
|
||||
MediumFlexibleTopAppBar(
|
||||
title = { Text(stringResource(R.string.tokens)) },
|
||||
actions = {
|
||||
AnimatedVisibility(visible = !isSearchExpanded) {
|
||||
IconButton(onClick = { isSearchExpanded = true }) {
|
||||
Icon(Icons.Default.Search, contentDescription = stringResource(R.string.search))
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
scrollBehavior = scrollBehavior
|
||||
)
|
||||
}
|
||||
},
|
||||
floatingActionButton = {
|
||||
FloatingActionButton(onClick = { showAddBottomSheet = true }) {
|
||||
@@ -154,7 +151,8 @@ fun TokensScreen(
|
||||
EmptyState(
|
||||
icon = Icons.Outlined.SearchOff,
|
||||
title = stringResource(R.string.empty_search_title),
|
||||
hint = stringResource(R.string.empty_search_hint)
|
||||
hint = stringResource(R.string.empty_search_hint),
|
||||
iconShape = MaterialShapes.Sunny.toShape()
|
||||
)
|
||||
}
|
||||
} else {
|
||||
@@ -214,12 +212,14 @@ fun TokensScreen(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||
@Composable
|
||||
private fun EmptyState(
|
||||
icon: ImageVector,
|
||||
title: String,
|
||||
hint: String,
|
||||
modifier: Modifier = Modifier,
|
||||
iconShape: Shape = MaterialShapes.Cookie9Sided.toShape(),
|
||||
actionLabel: String? = null,
|
||||
onActionClick: (() -> Unit)? = null
|
||||
) {
|
||||
@@ -233,15 +233,15 @@ private fun EmptyState(
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(96.dp)
|
||||
.clip(CircleShape)
|
||||
.background(MaterialTheme.colorScheme.surfaceContainerHighest),
|
||||
.clip(iconShape)
|
||||
.background(MaterialTheme.colorScheme.primaryContainer),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(44.dp),
|
||||
tint = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
tint = MaterialTheme.colorScheme.onPrimaryContainer
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(20.dp))
|
||||
@@ -471,16 +471,26 @@ fun TokenCard(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||
@Composable
|
||||
fun TokenIcon(token: Token) {
|
||||
val letter = token.issuer.takeIf { it.isNotBlank() }?.firstOrNull()?.uppercaseChar()
|
||||
?: token.serviceName.firstOrNull()?.uppercaseChar()
|
||||
?: '?'
|
||||
|
||||
// Deterministic per-token shape: keep 4 understated options, no randomness between recompositions
|
||||
val shapes = listOf(
|
||||
MaterialShapes.Circle,
|
||||
MaterialShapes.Cookie9Sided,
|
||||
MaterialShapes.Pill,
|
||||
MaterialShapes.Sunny,
|
||||
)
|
||||
val shape = shapes[abs(token.issuer.hashCode() * 31 + token.serviceName.hashCode()) % shapes.size]
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(48.dp)
|
||||
.clip(CircleShape)
|
||||
.clip(shape.toShape())
|
||||
.background(MaterialTheme.colorScheme.primaryContainer),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user