这是我的动画组合:
@Composable
fun AnimateWithFadingIn(modifier: Modifier = Modifier){
var isShowing by remember { mutableStateOf(false) }
val iconOffset by animateDpAsState(
targetValue = if (isShowing) 80.dp else (0).dp,
label = "",
animationSpec = tween(durationMillis = 1000)
)
val rotationAngle by animateFloatAsState(
targetValue = if (isShowing) 360f else 0f,
animationSpec = tween(durationMillis = 1000)
)
Column(
modifier = modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Row {
AnimatedVisibility(
visible = isShowing,
enter = slideInHorizontally(initialOffsetX = {it},animationSpec = tween(durationMillis = 1000)) + fadeIn(animationSpec = tween(durationMillis = 1000)),
exit = slideOutHorizontally (targetOffsetX = {it/2},animationSpec = tween(durationMillis = 1000)) + fadeOut(animationSpec = tween(durationMillis = 1000))
) {
Text("Text is showing")
}
if (isShowing){
Spacer(modifier = Modifier.width(8.dp))
}
IconButton(modifier = Modifier.size(40.dp).offset(x = iconOffset).rotate(degrees = rotationAngle), onClick = {isShowing = !isShowing}) {
Icon(imageVector = Icons.Default.Clear, contentDescription = null)
}
}
}
}
基于这一点trory将