import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.Alignment
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.animateColorAsState
@Composable
fun RichUIShowcase() {
var clicked by remember { mutableStateOf(false) }
var toggleOn by remember { mutableStateOf(false) }
val buttonSize by animateDpAsState(targetValue = if (clicked) 80.dp else 60.dp)
val buttonColor by animateColorAsState(targetValue = if (clicked) Color(0xFF6200EE) else Color(0xFF03DAC5))
Column(
modifier = Modifier.fillMaxSize().padding(16.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Button(
onClick = { clicked = !clicked },
modifier = Modifier.size(buttonSize),
colors = ButtonDefaults.buttonColors(containerColor = buttonColor)
) {
Text("Animated Button", color = Color.White)
}
Spacer(modifier = Modifier.height(24.dp))
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(16.dp)
) {
Card(
modifier = Modifier.weight(1f),
colors = CardDefaults.cardColors(containerColor = Color(0xFFE3F2FD))
) {
Box(
modifier = Modifier
.height(100.dp)
.fillMaxWidth(),
contentAlignment = Alignment.Center
) {
Text("Card 1", fontWeight = FontWeight.Bold, color = Color(0xFF0D47A1))
}
}
Card(
modifier = Modifier.weight(1f),
colors = CardDefaults.cardColors(containerColor = Color(0xFFFFF3E0))
) {
Box(
modifier = Modifier
.height(100.dp)
.fillMaxWidth(),
contentAlignment = Alignment.Center
) {
Text("Card 2", fontWeight = FontWeight.Bold, color = Color(0xFFE65100))
}
}
}
Spacer(modifier = Modifier.height(24.dp))
Row(
verticalAlignment = Alignment.CenterVertically
) {
Text(text = if (toggleOn) "Toggle is ON" else "Toggle is OFF", modifier = Modifier.padding(end = 8.dp))
Switch(checked = toggleOn, onCheckedChange = { toggleOn = it })
}
}
}This solution uses Jetpack Compose's remember and mutableStateOf to keep track of UI states like button click and toggle switch.
The animated button changes its size and color smoothly using animateDpAsState and animateColorAsState. When clicked, it toggles between two sizes and colors.
The custom layout uses a Row with two Card components side by side, each styled with different background colors and centered text.
The toggle switch updates a text label dynamically based on its state, demonstrating reactive UI updates.
All these features together show how advanced Compose techniques create rich, interactive, and visually appealing user interfaces.