> For the complete documentation index, see [llms.txt](https://notes.tejpratapsingh.com/_/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.tejpratapsingh.com/_/android-tips/interview/compose.md).

# Compose

### Fundamentals & Recomposition

1. Explain the difference between `remember` and `rememberSaveable` and when each is appropriate.
2. What triggers recomposition in Compose, and how does the compiler optimize it via stability inference?
3. How do `@Stable`, `@Immutable`, and `@NonRestartableComposable` annotations affect recomposition behavior?
4. Why is it problematic to pass unstable types (e.g., `ArrayList`, `ViewModel`) directly into Composable parameters?
5. What is the role of `SnapshotState` and how does it integrate with Compose's observation system?
6. Explain the difference between `derivedStateOf` and `remember(key)` — when would you choose one over the other?
7. What happens if you write `var text by remember { mutableStateOf("") }` inside a Composable versus hoisting it to a ViewModel?

### State Management & Architecture

8. How do you implement unidirectional data flow in a Compose-heavy application?
9. What are the trade-offs between `ViewModel` state holders versus plain class state holders in Compose?
10. How do you handle configuration changes (e.g., rotation) with Compose state without relying on `ViewModel`?
11. Describe the purpose and limitations of `CompositionLocal` — when is it appropriate to use versus avoid?
12. How would you share state between sibling Composables without passing callbacks through multiple layers?
13. What is the difference between `produceState`, `collectAsState`, and `collectAsStateWithLifecycle`?
14. How do you gracefully handle process death and restoration with Compose Navigation?

### Performance & Optimization

15. What is the "donut-hole skipping" optimization in Compose, and how do you ensure your code benefits from it?
16. How does `LazyColumn` differ from `RecyclerView` in terms of item recycling and composition strategy?
17. What is the cost of using `Modifier` chains extensively, and how do you optimize them?
18. When should you use `key` in `LazyColumn` or `LazyRow`, and what happens if you omit it?
19. How do you debug and fix recomposition loops or excessive recompositions in a large screen?
20. Explain the impact of using `BoxWithConstraints` or `SubcomposeLayout` on performance.
21. What tools do you use to measure Compose frame times and recomposition counts in production?

### Custom Layouts & Graphics

22. How would you build a custom layout using `Layout` composable? What are `MeasurePolicy` and `IntrinsicMeasurable`?
23. What is the difference between `SubcomposeLayout` and the standard `Layout` composable?
24. How do you create a custom `Modifier` using `Modifier.Node` versus the older `Modifier.composed` approach?
25. Explain how `DrawScope` and `Canvas` work in Compose — how do you handle touch events on custom drawn elements?
26. How would you implement a staggered grid layout before `LazyVerticalStaggeredGrid` existed in Compose?

### Navigation & Deep Linking

27. How does Compose Navigation differ from the Fragment-based Navigation Component in terms of lifecycle and back stack?
28. How do you handle nested navigation graphs with independent back stacks in Compose?
29. What are the challenges of using type-safe navigation with Compose Navigation, and how do you implement it?
30. How do you manage screen transitions and shared element transitions between destinations in Compose Navigation?
31. Explain how you would implement a bottom navigation bar with multiple back stacks using Compose Navigation.

### Interoperability & Migration

32. How do you embed a `View` inside Compose and vice versa? What are the lifecycle implications?
33. What is `AndroidView` and when should you prefer it over rewriting a custom view in Compose?
34. How do you gradually migrate a large XML-based codebase to Compose without a full rewrite?
35. What are the challenges of using Compose inside `RecyclerView` or `ViewPager2`?
36. How do you handle `WindowInsets` when mixing Compose and legacy View-based screens?

### Testing

37. How do you write unit tests for Composables? What is the role of `createComposeRule`?
38. What is semantic testing in Compose, and how do you use `SemanticsMatcher` and `SemanticsNodeInteraction`?
39. How do you test state hoisting and verify that state changes trigger recompositions correctly?
40. What are the limitations of Compose UI testing compared to Espresso, and how do you work around them?
41. How do you perform screenshot or visual regression testing for Compose UIs?

### Animation & Gestures

42. Explain the difference between `animate*AsState`, `updateTransition`, and `AnimatedContent`.
43. How do you implement a draggable list item with reordering in Compose?
44. What is the difference between `pointerInput` and `Modifier.draggable` / `Modifier.swipeable` / `Modifier.anchoredDraggable`?
45. How do you coordinate animations across multiple Composables using `Animatable` and coroutines?
46. How would you implement a shared element transition between two screens in Compose?

### Theming & Design Systems

47. How do you build a multi-theme design system in Compose that supports dynamic color, light/dark mode, and brand themes?
48. What is the role of `CompositionLocalProvider` in theming, and how do you avoid overusing it?
49. How do you handle typography scaling and accessibility font sizes gracefully in Compose layouts?
50. How do you implement a custom ripple effect or remove the default ripple in Material3 Compose?

### Build & Tooling

51. What Compose compiler metrics do you monitor (e.g., `reportsDestination`), and how do you act on them?
52. How does the Compose Compiler plugin differ from standard Kotlin compilation, and what version alignment issues have you encountered?
53. What is the impact of enabling/disabling `strongSkipping` mode in the Compose compiler?
54. How do you manage Compose version alignment across a multi-module project with different teams?

### System & Edge Cases

55. How do you handle `SurfaceView` or `TextureView` content (e.g., camera, video) within a Compose layout?
56. What are the implications of using Compose in a `Service` or `Widget` context (e.g., Glance)?
57. How do you manage memory leaks in Compose, particularly with `remember` holding references to lifecycle-bound objects?
58. How do you implement a responsive layout that adapts to foldable devices or large screens using Compose?
59. What is the `Recomposer` and when would you need to interact with it directly?
60. How do you handle text input fields with complex formatting (e.g., credit cards, phone numbers) in Compose?


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://notes.tejpratapsingh.com/_/android-tips/interview/compose.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
