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) ) } }
ConstraintLayout( 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() ) {
Column( modifier = Modifier.padding(end = 4.dp) ) { FabButton( rotation = 0f, padding = padding, elevation = elevation, buttonClick = childClick, fabItem = fabItem ) Spacer( modifier = Modifier.height(8.dp) ) } }}
@Composable fun FabButton( rotation : Float, elevation : Dp = 4.dp, endPadding : Dp = 3.dp, padding : Dp, fabItem: FabItem, buttonClick : () -> Unit ){
Row ( horizontalArrangement = Arrangement.End, verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(end = endPadding) ){ if (fabItem.title.isNotEmpty()){ Card ( elevation = elevation, backgroundColor = Purple500, ){ Text( text = fabItem.title, modifier = Modifier.padding( start = 10.dp, end = 10.dp, top = 4.dp, bottom = 4.dp ) ) } Spacer(modifier = Modifier.width(10.dp)) } Card ( elevation = elevation, backgroundColor = Purple500, shape = CircleShape, modifier = Modifier .clickable { buttonClick() } .rotate( if (!fabItem.isChild) { rotation } else 0f ) ){ Icon( imageVector = fabItem.imageResource, contentDescription = fabItem.title, tint = Color.White, modifier = Modifier .padding(padding) ) } } - 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:@Composable fun FabMenu( modifier: Modifier = Modifier, fabmenuBackground : Color = Color.White, childItems : List<FabItem>, childItemClick : (FabItem) -> Unit ) { val rotation = remember { Animatable(0f) } var fabState by remember { mutableStateOf(FabState.COLLAPSE) } Scaffold( modifier = modifier, floatingActionButton = { FloatingActionButton( onClick = { fabState = fabState.getAlternativestate() if (!childItems.isEmpty()) { rotation.animateTo( targetValue = if (fabState == FabState.EXPAND) { rotation.targetValue + 45f } else rotation.targetValue - 45f, animationSpec = tween(100, easing = LinearEasing) ) } }, backgroundColor = if (fabState == FabState.EXPAND) LightBlue700 else MaterialTheme.colors.primary ) { Icon( imageVector = if (fabState == FabState.COLLAPSE) Icons.Default.Add else Icons.Default.Clear, contentDescription = null, tint = Color.White, modifier = Modifier.rotate(rotation.value) ) } }, isFloatingActionButtonDocked = true, floatingActionButtonPosition = FabPosition.End, content = { Column(Modifier.background(fabmenuBackground)) { childItems.forEach { item -> AnimatedVisibility( visible = fabState == FabState.EXPAND, enter = fadeIn(), exit = fadeOut(), modifier = Modifier.fillMaxWidth() ) { Card( backgroundColor = if (item.isChild) Purple700 else Purple500, shape = CircleShape,
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.