data class FabItem( val imageResource : ImageVector, val title : String, val isChild :…
- User
data class FabItem( val imageResource : ImageVector, val title : String, val isChild : Boolean = false )
@Composable fun FabMenu( modifier: Modifier = Modifier, fabmenuBackground : Color = Color.White, childItems : List, childItemClick : (FabItem) -> Unit ){ val rotation = remember { Animatable(0f) } val scope = rememberCoroutineScope() var fabState by remember { mutableStateOf(FabState.COLLAPSE) } val rootFabClicked = { scope.launch { fabState = fabState.getAlternativestate() rotation.animateTo( targetValue = if (fabState == FabState.EXPAND) { rotation.targetValue + 45f } else rotation.targetValue - 45f, animationSpec = tween(100, easing = LinearEasing) ) } }
codeConstraintLayout( modifier = modifier .fillMaxSize() .background(if (fabState == FabState.EXPAND) fabmenuBackground else Color.Transparent) ) { val (fabmenu) = createRefs() Column( horizontalAlignment = Alignment.End, modifier = Modifier .padding(20.dp) .constrainAs(fabmenu) { bottom.linkTo(parent.bottom) end.linkTo(parent.end) } ) { LazyColumn( horizontalAlignment = Alignment.End ){ itemsIndexed(childItems){ _index, _item-> FabButtonChild( fabState = fabState, padding = 8.dp, fabItem = _item ){ childItemClick(_item) } } } Spacer( modifier = Modifier.height(8.dp) ) FabButton( padding = 16.dp, elevation = 8.dp, rotation = rotation.value, fabItem = FabItem(Icons.Default.Add,"", false), endPadding = 0.dp, buttonClick = {rootFabClicked()} ) } }}
@OptIn(ExperimentalAnimationApi::class) @Composable fun FabButtonChild( fabState : FabState, padding : Dp, elevation : Dp = 4.dp, fabItem: FabItem, childClick : () -> Unit ){ AnimatedVisibility( visible = fabState == FabState.EXPAND, enter = scaleIn(), exit = scaleOut() ) {
- Assistant
As an AI language model, I cannot provide you with the exact output of this code as it requires running and executing the code to see the output. However, this code appears to be a Kotlin code for creating a Floating Action Button menu. The
FabMenu()function takes in parameters such aschildItems, which is a list ofFabItemthat contains the image vector, title, and a boolean to check if it's a child item. The functionFabButtonChild()creates an animated visibility for the child buttons, whileFabButton()creates a row layout for the child buttons with aCard,Text, andIcon. TheFabMenuDisplay()function previews theFabMenu()with the specified parameters, such as the list ofFabItemand thefabmenuBackgroundcolor. - User
rewrite that code to minimize boilerplate and use scaffold
- Assistant
- User
rewrite it so it all just in one scaffold body
- Assistant
- User
wrong. rewrite it so it all code is on scaffold {} brackets, no other @Composable functions
- Assistant
- User
where is animatevisability?
- Assistant
I apologize for the omission. Here is the updated version of the code that includes the
AnimatedVisibilitycomposable for the child items:code