Skip to content

Commit 1a147e4

Browse files
committed
Refactor EnhancedTextField to remove animated color transitions, simplifying logic and reducing overhead.
1 parent ab08f08 commit 1a147e4

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

composeApp/src/wasmJsMain/kotlin/love/forte/simbot/codegen/components/EnhancedTextField.kt

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package love.forte.simbot.codegen.components
22

3-
import androidx.compose.animation.animateColorAsState
43
import androidx.compose.animation.animateContentSize
54
import androidx.compose.animation.core.Spring
65
import androidx.compose.animation.core.spring
7-
import androidx.compose.animation.core.tween
86
import androidx.compose.foundation.interaction.MutableInteractionSource
97
import androidx.compose.foundation.interaction.collectIsFocusedAsState
108
import androidx.compose.foundation.layout.fillMaxWidth
@@ -43,29 +41,34 @@ fun EnhancedTextField(
4341
val interactionSource = remember { MutableInteractionSource() }
4442
val isFocused by interactionSource.collectIsFocusedAsState()
4543

46-
val borderColor by animateColorAsState(
47-
targetValue = when {
48-
isError -> MaterialTheme.colorScheme.error
49-
isFocused -> MaterialTheme.colorScheme.primary
50-
else -> MaterialTheme.colorScheme.outline.copy(alpha = 0.8f)
51-
},
52-
animationSpec = tween(durationMillis = 200),
53-
label = "边框颜色动画"
54-
)
44+
// val borderColor by animateColorAsState(
45+
// targetValue = when {
46+
// isError -> MaterialTheme.colorScheme.error
47+
// isFocused -> MaterialTheme.colorScheme.primary
48+
// else -> MaterialTheme.colorScheme.outline.copy(alpha = 0.8f)
49+
// },
50+
// animationSpec = tween(durationMillis = 200),
51+
// label = "边框颜色动画"
52+
// )
5553

56-
// val backgroundColor = when {
57-
// isFocused -> MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.3f)
58-
// else -> MaterialTheme.colorScheme.surface
59-
// }
54+
val borderColor = when {
55+
isError -> MaterialTheme.colorScheme.error
56+
isFocused -> MaterialTheme.colorScheme.primary
57+
else -> MaterialTheme.colorScheme.outline.copy(alpha = 0.65f)
58+
}
6059

61-
val backgroundColor by animateColorAsState(
62-
targetValue = when {
63-
isFocused -> MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.15f)
64-
else -> MaterialTheme.colorScheme.surface
65-
},
66-
animationSpec = tween(durationMillis = 130),
67-
label = "背景颜色动画"
68-
)
60+
// val backgroundColor = when {
61+
// isFocused -> MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.15f)
62+
// else -> MaterialTheme.colorScheme.surface
63+
// }
64+
65+
// val backgroundColor by animateColorAsState(
66+
// targetValue = when {
67+
// isFocused -> MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.15f)
68+
// else -> MaterialTheme.colorScheme.surface
69+
// },
70+
// label = "背景颜色动画"
71+
// )
6972

7073
OutlinedTextField(
7174
value = value,
@@ -107,8 +110,8 @@ fun EnhancedTextField(
107110
colors = OutlinedTextFieldDefaults.colors(
108111
focusedBorderColor = borderColor,
109112
unfocusedBorderColor = borderColor.copy(alpha = 0.7f),
110-
focusedContainerColor = backgroundColor,
111-
unfocusedContainerColor = backgroundColor,
113+
// focusedContainerColor = backgroundColor,
114+
// unfocusedContainerColor = backgroundColor,
112115
focusedLabelColor = MaterialTheme.colorScheme.primary,
113116
unfocusedLabelColor = MaterialTheme.colorScheme.onSurfaceVariant,
114117
errorBorderColor = MaterialTheme.colorScheme.error,

0 commit comments

Comments
 (0)