Skip to content

Commit 0f23706

Browse files
committed
improvement(UI): Use M3 defaultEffectsSpec for color state animations
1 parent 5210754 commit 0f23706

8 files changed

Lines changed: 39 additions & 9 deletions

File tree

common/src/androidMain/kotlin/com/artemchep/keyguard/android/BaseActivity.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import androidx.activity.compose.setContent
1111
import androidx.appcompat.app.AppCompatActivity
1212
import androidx.browser.customtabs.CustomTabsIntent
1313
import androidx.compose.animation.animateColorAsState
14+
import androidx.compose.material3.MaterialTheme
1415
import androidx.compose.material3.Surface
1516
import androidx.compose.material3.contentColorFor
1617
import androidx.compose.runtime.Composable
@@ -121,7 +122,10 @@ abstract class BaseActivity : AppCompatActivity(), DIAware {
121122
setContent {
122123
KeyguardTheme {
123124
val containerColor = activityContainerColor()
124-
val containerColorAnimatedState = animateColorAsState(containerColor)
125+
val containerColorAnimatedState = animateColorAsState(
126+
targetValue = containerColor,
127+
animationSpec = MaterialTheme.motionScheme.defaultEffectsSpec(),
128+
)
125129
val contentColor = activityContentColor(containerColorAnimatedState.value)
126130
Surface(
127131
modifier = Modifier.semantics {

common/src/androidMain/kotlin/com/artemchep/keyguard/android/sshagent/SshRequestActivity.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,10 @@ internal class SshRequestActivity : BaseActivity() {
176176
val initialY = 48.dp
177177
mutableStateOf(initialY)
178178
}
179-
val dimColor by animateColorAsState(dimColorTarget)
179+
val dimColor by animateColorAsState(
180+
targetValue = dimColorTarget,
181+
animationSpec = MaterialTheme.motionScheme.defaultEffectsSpec(),
182+
)
180183
val contentScale by animateFloatAsState(
181184
targetValue = contentScaleTarget,
182185
animationSpec = tween(durationMillis = 300),

common/src/commonMain/kotlin/com/artemchep/keyguard/feature/confirmation/ConfirmationScreen.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,10 @@ private fun ConfirmationFileItem(
474474
} else {
475475
MaterialTheme.colorScheme.error
476476
}
477-
val colorState = animateColorAsState(colorTarget)
477+
val colorState = animateColorAsState(
478+
targetValue = colorTarget,
479+
animationSpec = MaterialTheme.motionScheme.defaultEffectsSpec(),
480+
)
478481
Icon(
479482
imageVector = Icons.Outlined.AttachFile,
480483
contentDescription = null,

common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/settings/SettingListScreen.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ fun rememberSettingsItems(
235235

236236
val targetTint =
237237
if (isPurchased) MaterialTheme.colorScheme.primary else LocalContentColor.current
238-
val tint by animateColorAsState(targetValue = targetTint)
238+
val tint by animateColorAsState(
239+
targetValue = targetTint,
240+
animationSpec = MaterialTheme.motionScheme.defaultEffectsSpec(),
241+
)
239242
Icon(
240243
Icons.Outlined.KeyguardPremium,
241244
null,

common/src/commonMain/kotlin/com/artemchep/keyguard/feature/home/vault/component/SearchTextField.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ private fun Modifier.searchTextFieldBackground(
389389
val colorState =
390390
animateColorAsState(
391391
targetValue = if (isHighlightedState.value) colorTarget else colorTarget.combineAlpha(0f),
392+
animationSpec = MaterialTheme.motionScheme.defaultEffectsSpec(),
392393
label = "SearchFieldBackground",
393394
)
394395

common/src/commonMain/kotlin/com/artemchep/keyguard/feature/largetype/LargeTypeScreen.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ private fun SymbolItem(
181181
MaterialTheme.colorScheme
182182
.surfaceColorAtElevation(backgroundElevation)
183183
}
184-
val backgroundColorState = animateColorAsState(targetBackgroundColor)
184+
val backgroundColorState = animateColorAsState(
185+
targetValue = targetBackgroundColor,
186+
animationSpec = MaterialTheme.motionScheme.defaultEffectsSpec(),
187+
)
185188
Modifier
186189
.padding(2.dp)
187190
.clip(RoundedCornerShape(4.dp))

common/src/commonMain/kotlin/com/artemchep/keyguard/feature/yubikey/YubiKey.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ fun YubiKeyUsbCard(
9191
)
9292
val colorTarget =
9393
if (isActive) MaterialTheme.colorScheme.primary else LocalContentColor.current
94-
val color by animateColorAsState(colorTarget)
94+
val color by animateColorAsState(
95+
targetValue = colorTarget,
96+
animationSpec = MaterialTheme.motionScheme.defaultEffectsSpec(),
97+
)
9598
Icon(
9699
Icons.Outlined.Usb,
97100
modifier = Modifier

common/src/commonMain/kotlin/com/artemchep/keyguard/ui/TextItem.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,7 @@ private fun TextFieldLabel(
936936
.combineAlpha(HighEmphasisAlpha)
937937
val textColor by animateColorAsState(
938938
targetValue = if (expanded) expandedTextColor else normalTextColor,
939+
animationSpec = MaterialTheme.motionScheme.defaultEffectsSpec(),
939940
)
940941

941942
Text(
@@ -1485,7 +1486,10 @@ private fun FlatTextFieldSurface(
14851486
.combineAlpha(0.1f)
14861487
.compositeOver(MaterialTheme.colorScheme.surfaceVariant)
14871488
}
1488-
val borderColor by animateColorAsState(targetValue = borderColorTarget)
1489+
val borderColor by animateColorAsState(
1490+
targetValue = borderColorTarget,
1491+
animationSpec = MaterialTheme.motionScheme.defaultEffectsSpec(),
1492+
)
14891493
val shape = surfaceShape(
14901494
shapeState = shapeState,
14911495
expressive = expressive,
@@ -1551,7 +1555,10 @@ fun FlatTextFieldBadge(
15511555
text: String,
15521556
icon: ImageVector? = null,
15531557
) {
1554-
val backgroundColorState = animateColorAsState(backgroundColor)
1558+
val backgroundColorState = animateColorAsState(
1559+
targetValue = backgroundColor,
1560+
animationSpec = MaterialTheme.motionScheme.defaultEffectsSpec(),
1561+
)
15551562
val contentColor = run {
15561563
val color = if (backgroundColor.luminance() > 0.5f) {
15571564
Color.Black
@@ -1561,7 +1568,10 @@ fun FlatTextFieldBadge(
15611568
val tint = backgroundColor.copy(alpha = 0.1f)
15621569
tint.compositeOver(color)
15631570
}
1564-
val contentColorState = animateColorAsState(contentColor)
1571+
val contentColorState = animateColorAsState(
1572+
targetValue = contentColor,
1573+
animationSpec = MaterialTheme.motionScheme.defaultEffectsSpec(),
1574+
)
15651575
Row(
15661576
modifier = modifier
15671577
.clip(MaterialTheme.shapes.small)

0 commit comments

Comments
 (0)