Compose Part 5
Q41. How do you perform screenshot or visual regression testing for Compose UIs?
// Paparazzi test: Fast, no emulator, deterministic pixel comparison.
class ProfileCardScreenshotTest {
@get:Rule
val paparazzi = Paparazzi(
deviceConfig = DeviceConfig.PIXEL_5,
theme = "android:Theme.Material3.Light.NoActionBar"
)
@Test
fun `profile card default state`() {
paparazzi.snapshot {
AppTheme {
ProfileCard(
user = User(
name = "Alex Johnson",
role = "Lead Developer",
avatarUrl = null // Use placeholder in UI
),
onClick = {}
)
}
}
}
@Test
fun `profile card dark theme`() {
paparazzi.snapshot {
AppTheme(darkTheme = true) {
ProfileCard(
user = User(name = "Alex Johnson", role = "Lead Developer", avatarUrl = null),
onClick = {}
)
}
}
}
}
// Compose Preview Screenshot Testing (Android Studio / Gradle plugin):
// 1. Apply plugin: id("com.android.compose.screenshot") version "0.0.1-alpha05"
// 2. Annotate previews:
@Preview(device = "id:pixel_5")
@Composable
fun ProfileCardPreview() {
AppTheme { ProfileCard(User("Alex", "Dev", null), {}) }
}
// Gradle generates reference screenshots and fails on diff:
// ./gradlew updateDebugScreenshotTest
// ./gradlew validateDebugScreenshotTestQ42. Explain the difference between animate*AsState, updateTransition, and AnimatedContent.
animate*AsState, updateTransition, and AnimatedContent.Q43. How do you implement a draggable list item with reordering in Compose?
Q44. What is the difference between pointerInput and Modifier.draggable / Modifier.swipeable / Modifier.anchoredDraggable?
pointerInput and Modifier.draggable / Modifier.swipeable / Modifier.anchoredDraggable?Q45. How do you coordinate animations across multiple Composables using Animatable and coroutines?
Animatable and coroutines?Q46. How would you implement a shared element transition between two screens in Compose?
Q47. How do you build a multi-theme design system in Compose that supports dynamic color, light/dark mode, and brand themes?
Q48. What is the role of CompositionLocalProvider in theming, and how do you avoid overusing it?
CompositionLocalProvider in theming, and how do you avoid overusing it?Q49. How do you handle typography scaling and accessibility font sizes gracefully in Compose layouts?
Q50. How do you implement a custom ripple effect or remove the default ripple in Material3 Compose?
Last updated