refactor: adopt M3 Expressive components from material3 1.11.0-alpha06 (#5063)

This commit is contained in:
James Rich 2026-04-10 21:10:03 -05:00 committed by GitHub
parent a6423d0a0f
commit 3794c79dae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 128 additions and 69 deletions

View file

@ -19,7 +19,7 @@ package org.meshtastic.core.ui.component
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.IconToggleButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@ -36,6 +36,7 @@ import org.meshtastic.core.resources.Res
import org.meshtastic.core.resources.hide_password
import org.meshtastic.core.resources.show_password
import org.meshtastic.core.ui.icon.MeshtasticIcons
import org.meshtastic.core.ui.icon.Visibility
import org.meshtastic.core.ui.icon.VisibilityOff
@Composable
@ -63,10 +64,9 @@ fun EditPasswordPreference(
onFocusChanged = {},
visualTransformation = if (isPasswordVisible) VisualTransformation.None else PasswordVisualTransformation(),
trailingIcon = {
IconButton(onClick = { isPasswordVisible = !isPasswordVisible }) {
IconToggleButton(checked = isPasswordVisible, onCheckedChange = { isPasswordVisible = it }) {
Icon(
imageVector =
if (isPasswordVisible) MeshtasticIcons.VisibilityOff else MeshtasticIcons.VisibilityOff,
imageVector = if (isPasswordVisible) MeshtasticIcons.VisibilityOff else MeshtasticIcons.Visibility,
contentDescription =
if (isPasswordVisible) {
stringResource(Res.string.hide_password)

View file

@ -23,6 +23,7 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ElevatedButton
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
@ -43,22 +44,28 @@ fun PreferenceFooter(
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically,
) {
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
val mediumHeight = ButtonDefaults.MediumContainerHeight
if (negativeText != null) {
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
ElevatedButton(
modifier = Modifier.height(48.dp).weight(1f),
shapes = ButtonDefaults.shapesFor(mediumHeight),
modifier = Modifier.height(mediumHeight).weight(1f),
colors = ButtonDefaults.filledTonalButtonColors(),
onClick = onNegativeClicked,
) {
Text(text = negativeText)
Text(text = negativeText, style = ButtonDefaults.textStyleFor(mediumHeight))
}
}
if (positiveText != null) {
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
ElevatedButton(
modifier = Modifier.height(48.dp).weight(1f),
shapes = ButtonDefaults.shapesFor(mediumHeight),
modifier = Modifier.height(mediumHeight).weight(1f),
colors = ButtonDefaults.buttonColors(),
onClick = { if (enabled) onPositiveClicked() },
) {
Text(text = positiveText)
Text(text = positiveText, style = ButtonDefaults.textStyleFor(mediumHeight))
}
}
}

View file

@ -29,6 +29,7 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Surface
@ -240,21 +241,33 @@ fun ScannedQrCodeDialog(
val unselectedColors =
ButtonDefaults.outlinedButtonColors(contentColor = MaterialTheme.colorScheme.onSurface)
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
val mediumHeight = ButtonDefaults.MediumContainerHeight
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
OutlinedButton(
onClick = { shouldReplace = false },
modifier = Modifier.height(48.dp).weight(1f),
shapes = ButtonDefaults.shapesFor(mediumHeight),
modifier = Modifier.height(mediumHeight).weight(1f),
colors = if (!shouldReplace) selectedColors else unselectedColors,
) {
Text(text = stringResource(Res.string.add))
Text(
text = stringResource(Res.string.add),
style = ButtonDefaults.textStyleFor(mediumHeight),
)
}
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
OutlinedButton(
onClick = { shouldReplace = true },
modifier = Modifier.height(48.dp).weight(1f),
shapes = ButtonDefaults.shapesFor(mediumHeight),
modifier = Modifier.height(mediumHeight).weight(1f),
enabled = incoming.lora_config != null,
colors = if (shouldReplace) selectedColors else unselectedColors,
) {
Text(text = stringResource(Res.string.replace))
Text(
text = stringResource(Res.string.replace),
style = ButtonDefaults.textStyleFor(mediumHeight),
)
}
}
}