-
Notifications
You must be signed in to change notification settings - Fork 707
refactor(ui): Optimize card component style and color management #1381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,7 +46,9 @@ import androidx.compose.material3.Button | |
| import androidx.compose.material3.CardDefaults | ||
| import androidx.compose.material3.DropdownMenu | ||
| import androidx.compose.material3.DropdownMenuItem | ||
| import androidx.compose.material3.Card | ||
| import androidx.compose.material3.ElevatedCard | ||
| import androidx.compose.material3.surfaceColorAtElevation | ||
| import androidx.compose.material3.ExperimentalMaterial3Api | ||
| import androidx.compose.material3.Icon | ||
| import androidx.compose.material3.IconButton | ||
|
|
@@ -473,29 +475,30 @@ private fun KStatusCard( | |
| UninstallDialog(showDialog = showUninstallDialog, navigator) | ||
| } | ||
|
|
||
| val cardBackgroundColor = when (kpState) { | ||
| val (cardBackgroundColor, cardContentColor) = when (kpState) { | ||
| APApplication.State.KERNELPATCH_INSTALLED -> { | ||
| MaterialTheme.colorScheme.primary | ||
| MaterialTheme.colorScheme.primary to MaterialTheme.colorScheme.onPrimary | ||
| } | ||
|
|
||
| APApplication.State.KERNELPATCH_NEED_UPDATE, APApplication.State.KERNELPATCH_NEED_REBOOT -> { | ||
| MaterialTheme.colorScheme.secondary | ||
| MaterialTheme.colorScheme.secondary to MaterialTheme.colorScheme.onSecondary | ||
| } | ||
|
|
||
| else -> { | ||
| MaterialTheme.colorScheme.secondaryContainer | ||
| MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp) to MaterialTheme.colorScheme.onSurface | ||
| } | ||
| } | ||
|
|
||
| ElevatedCard( | ||
| Card( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just want to notice to you, you no need to switch to Card, because ElevatedCard basically is an alias of Card itself @Composable
fun ElevatedCard(
modifier: Modifier = Modifier,
shape: Shape = CardDefaults.elevatedShape,
colors: CardColors = CardDefaults.elevatedCardColors(),
elevation: CardElevation = CardDefaults.elevatedCardElevation(),
content: @Composable ColumnScope.() -> Unit,
) =
Card(
modifier = modifier,
shape = shape,
border = null,
elevation = elevation,
colors = colors,
content = content,
)This is a code snippet of material3-android library, as you can see, ElevatedCard is an card without border, that is all And if you want unify, you should package your own Card control, NOT CHANGE EVERYWHERE TO WASTE, THAT IS A NIGHTMARE |
||
| onClick = { | ||
| if (kpState != APApplication.State.KERNELPATCH_INSTALLED) { | ||
| navigator.navigate(InstallModeSelectScreenDestination) | ||
| } | ||
| }, | ||
| colors = CardDefaults.elevatedCardColors(containerColor = cardBackgroundColor), | ||
| elevation = CardDefaults.cardElevation( | ||
| defaultElevation = if (kpState == APApplication.State.UNKNOWN_STATE) 0.dp else 6.dp | ||
| shape = RoundedCornerShape(20.dp), | ||
| colors = CardDefaults.cardColors( | ||
| containerColor = cardBackgroundColor, | ||
| contentColor = cardContentColor | ||
| ) | ||
| ) { | ||
| Column( | ||
|
|
@@ -644,10 +647,9 @@ private fun KStatusCard( | |
|
|
||
| @Composable | ||
| private fun AStatusCard(apState: APApplication.State) { | ||
| ElevatedCard( | ||
| colors = CardDefaults.elevatedCardColors(containerColor = run { | ||
| MaterialTheme.colorScheme.secondaryContainer | ||
| }) | ||
| Card( | ||
| shape = RoundedCornerShape(20.dp), | ||
| colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp)) | ||
| ) { | ||
| Column( | ||
| modifier = Modifier | ||
|
|
@@ -858,7 +860,10 @@ private fun getDeviceInfo(): String { | |
|
|
||
| @Composable | ||
| private fun InfoCard(kpState: APApplication.State, apState: APApplication.State) { | ||
| ElevatedCard { | ||
| Card( | ||
| shape = RoundedCornerShape(20.dp), | ||
| colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp)) | ||
| ) { | ||
| Column( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
|
|
@@ -952,7 +957,10 @@ fun UpdateCard() { | |
| fun LearnMoreCard() { | ||
| val uriHandler = LocalUriHandler.current | ||
|
|
||
| ElevatedCard { | ||
| Card( | ||
| shape = RoundedCornerShape(20.dp), | ||
| colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp)) | ||
| ) { | ||
| Row( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you want to do
I think you should read Android's UI design documents first Click There
You can see from this document, card colors use
surfaceContainer,we already have
surfacesurfaceContainerLowestsurfaceContainerLowsurfaceContainersurfaceContainerHighsurfaceContainerHighest6 elevation colors in theme, why manually calc that?I think manually calc elevation colors is unnecessary, and will cause more rendering time, because you are do math calc internally rather than directly using data calculated at application startup!