Repository: android/compose-samples
File: Jetsnack/app/src/main/java/com/example/jetsnack/ui/home/cart/Cart.kt (Kotlin)

Code before:
                        (offsetX < -10f && offsetX > -300f) -> ((offsetX * -24) / 350).toInt().dp

                        else -> 24.dp
                    }
                    val background = if (offsetX >= -450) {
                        Color.Transparent
                    } else {
                        JetsnackTheme.colors.error
                    }
                    Row(
                        modifier = Modifier
                            .fillMaxWidth()
                            .heightIn(120.dp, 120.dp)
                            .padding(end = paddingRight)
                            .background(background),
                        horizontalArrangement = Arrangement.End,
                        verticalAlignment = Alignment.CenterVertically

                    ) {
                        val size = when {
                            offsetX == 0f -> 0.dp
                            (offsetX < -0f) -> (offsetX / -5).dp
                            (offsetX < -200f) -> (offsetX * -10).dp
                            else -> 0.dp
                        }
                        val sizeModifier = if (offsetX > -300f) {
                            Modifier.size(size)
                        } else {
                            Modifier
                                .height(size * 1.8f)
                                .width(size * 1.8f)
                        }
                        val shape = if (offsetX >= -300) CircleShape else RoundedCornerShape(30.dp)
                        Box(
                            modifier = Modifier
                                .clip(shape)
                                .background(JetsnackTheme.colors.error)
                                .then(sizeModifier)
                        ) {
                            Row(
                                modifier = Modifier
                                    .fillMaxWidth()
                                    .fillMaxHeight(),
                                horizontalArrangement = Arrangement.Center,
                                verticalAlignment = Alignment.CenterVertically
                            ) {
                                if (offsetX < -150f && offsetX > -450) {
                                    val iconAlpha = if (offsetX < -250) 0.5f else 1f
                                    Icon(
                                        imageVector = Icons.Filled.DeleteForever,
                                        modifier = Modifier

Review comment (suggestion):
Rather than changing the layout size, could we use a `graphicsLayer` modifier to scale the item as this will only require re-draw, no re-layout.

Code after:
                    /*Background color changes from light gray to red when the
                    swipe to delete with exceeds 160.dp*/
                    val backgroundColor = if (offsetX < -160.dp) {
                        JetsnackTheme.colors.error
                    } else {
                        JetsnackTheme.colors.uiFloated
                    }
                    Column(
                        modifier = Modifier
                            .fillMaxWidth()
                            .fillMaxHeight()
                            .background(backgroundColor),
                        horizontalAlignment = Alignment.End,
                        verticalArrangement = Arrangement.Center
                    ) {
                        // Set 4.dp padding only if offset is bigger than 160.dp
                        val padding: Dp by animateDpAsState(
                            if (offsetX > -160.dp) 4.dp else 0.dp
                        )
                        Box(
                            Modifier
                                .width(offsetX * -1)
                                .padding(padding)
                        ) {
                            // Height equals to width removing padding
                            val height = (offsetX + 8.dp) * -1
                            Surface(
                                modifier = Modifier
                                    .fillMaxWidth()
                                    .height(height)
                                    .align(Alignment.Center),
                                shape = CircleShape,
                                color = JetsnackTheme.colors.error
                            ) {
                                Box(
                                    modifier = Modifier.fillMaxSize(),
                                    contentAlignment = Alignment.Center
                                ) {
                                    // Icon must be visible while in this width range
                                    if (offsetX < -40.dp && offsetX > -152.dp) {
                                        // Icon alpha decreases as it is about to disappear
                                        val iconAlpha: Float by animateFloatAsState(
                                            if (offsetX < -120.dp) 0.5f else 1f
                                        )

                                        Icon(
                                            imageVector = Icons.Filled.DeleteForever,
                                            modifier = Modifier
                                                .size(16.dp)
                                                .graphicsLayer(alpha = iconAlpha),
                                            tint = JetsnackTheme.colors.uiBackground,