in Jetchat/app/src/main/java/com/example/compose/jetchat/components/AnimatingFabContent.kt [38:98]
fun AnimatingFabContent(
icon: @Composable () -> Unit,
text: @Composable () -> Unit,
modifier: Modifier = Modifier,
extended: Boolean = true
) {
val currentState = if (extended) ExpandableFabStates.Extended else ExpandableFabStates.Collapsed
val transition = updateTransition(currentState)
val textOpacity by transition.animateFloat(
transitionSpec = {
if (targetState == ExpandableFabStates.Collapsed) {
tween(
easing = LinearEasing,
durationMillis = (transitionDuration / 12f * 5).roundToInt() // 5 / 12 frames
)
} else {
tween(
easing = LinearEasing,
delayMillis = (transitionDuration / 3f).roundToInt(), // 4 / 12 frames
durationMillis = (transitionDuration / 12f * 5).roundToInt() // 5 / 12 frames
)
}
}
) { progress ->
if (progress == ExpandableFabStates.Collapsed) {
0f
} else {
1f
}
}
val fabWidthFactor by transition.animateFloat(
transitionSpec = {
if (targetState == ExpandableFabStates.Collapsed) {
tween(
easing = FastOutSlowInEasing,
durationMillis = transitionDuration
)
} else {
tween(
easing = FastOutSlowInEasing,
durationMillis = transitionDuration
)
}
}
) { progress ->
if (progress == ExpandableFabStates.Collapsed) {
0f
} else {
1f
}
}
// Using functions instead of Floats here can improve performance, preventing recompositions.
IconAndTextRow(
icon,
text,
{ textOpacity },
{ fabWidthFactor },
modifier = modifier
)
}