SpringActivity.kt

Home   »   SpringActivity.kt

@ExperimentalAnimationApi
@Composable
private fun ExpandableFabSpringHighBouncyMediumStiffness(modifier: Modifier = Modifier,) {
    val expanded = remember { mutableStateOf(false) }
    FloatingActionButton(
        modifier = modifier,
        onClick = { expanded.value = expanded.value.not() },
        content = {
            Row(
                modifier = Modifier.padding(horizontal = 16.dp),
                horizontalArrangement = Arrangement.Center,
                verticalAlignment = Alignment.CenterVertically,
            ) {
                Icon(
                    Icons.Default.Add,
                    contentDescription = null,
                )
                AnimatedVisibility(
                    visible = expanded.value,
                    enter = fadeIn() + slideInHorizontally(
                        animationSpec = spring(
                            dampingRatio = Spring.DampingRatioHighBouncy,
                            stiffness = Spring.StiffnessMedium
                        )
                    ),
                    exit = fadeOut() + slideOutHorizontally(
                        animationSpec = spring(
                            dampingRatio = Spring.DampingRatioHighBouncy,
                            stiffness = Spring.StiffnessMedium
                        )
                    ),
                ) {
                    Text(text = getString(R.string.button_add_item), modifier = Modifier.padding(start = 4.dp))
                }
            }
        }
    )
}

Leave a Reply

Your email address will not be published. Required fields are marked *