修复点击"今天"按钮标题栏抖动:alpha 渐变替代条件渲染
点击"今天"后 showToday 变为 false,按钮从布局移除导致 Row 高度 跳变 3px(85→82),引起标题栏抖动。改为始终保留按钮在布局中, 用 graphicsLayer alpha + animateFloatAsState 做淡入淡出动画, clickable(enabled) 控制可点击性,Row 高度不再变化。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
3a3e6014d8
commit
40c34f0606
@ -1,6 +1,7 @@
|
|||||||
package plus.rua.project.ui
|
package plus.rua.project.ui
|
||||||
|
|
||||||
import androidx.compose.animation.AnimatedContent
|
import androidx.compose.animation.AnimatedContent
|
||||||
|
import androidx.compose.animation.core.animateFloatAsState
|
||||||
import androidx.compose.animation.core.tween
|
import androidx.compose.animation.core.tween
|
||||||
import androidx.compose.animation.slideInVertically
|
import androidx.compose.animation.slideInVertically
|
||||||
import androidx.compose.animation.slideOutVertically
|
import androidx.compose.animation.slideOutVertically
|
||||||
@ -18,6 +19,9 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.graphicsLayer
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.ui.layout.onSizeChanged
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
|
|
||||||
@ -83,14 +87,19 @@ fun MonthHeader(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
if (showToday && onToday != null) {
|
val todayAlpha by animateFloatAsState(
|
||||||
|
targetValue = if (showToday && onToday != null) 1f else 0f,
|
||||||
|
animationSpec = tween(200)
|
||||||
|
)
|
||||||
|
if (onToday != null) {
|
||||||
Text(
|
Text(
|
||||||
text = "今天",
|
text = "今天",
|
||||||
color = MaterialTheme.colorScheme.primary,
|
color = MaterialTheme.colorScheme.primary,
|
||||||
fontSize = 14.sp,
|
fontSize = 14.sp,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
.graphicsLayer { alpha = todayAlpha }
|
||||||
.clip(RoundedCornerShape(12.dp))
|
.clip(RoundedCornerShape(12.dp))
|
||||||
.clickable(onClick = onToday)
|
.clickable(enabled = showToday, onClick = onToday)
|
||||||
.padding(horizontal = 10.dp, vertical = 4.dp)
|
.padding(horizontal = 10.dp, vertical = 4.dp)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user