Hidden Gems in Jetpack Compose: My Journey
1. The Joy of Discovering the Unexpected
2. Small Changes, Big Impact
3. Performance Boosters
4. Design & Animation Magic
5. Developer Experience Lifesavers
6. State Management Secrets
7. Lesser-Known Composables
8. Testing & Debugging Insights
9. Community & Inspiration
10. The Adventure Continues
Jetpack Compose Hidden Gems & Powerful Features
- SubcomposeLayout – Conditional child measurement.
- Layout – Fully custom layouts.
- onGloballyPositioned – Get size/position post-layout.
- Placeable API – Fine-grained control during layout.
- Constraints – Custom size constraints in layouts.
- MeasurePolicy – Define custom measurement rules.
- withConstraints – React to parent constraints.
- Spacer with weight – Dynamic spacing in Rows/Columns.
- Modifier.layoutId – Use in ConstraintLayout.
- BoxWithConstraints – Compose adaptive UI layouts.
Gesture & Interaction
- combinedClickable – Handle single, double tap, long press.
- pointerInput – Custom gestures and touch handling.
- Draggable – Custom drag behavior.
- swipeable – Swipe-based animations.
- detectTapGestures – Detect double taps, long press, and single taps in one place.
- nestedScroll – Advanced scroll handling.
- scrollable – Custom scroll orientation.
- tapGestureFilter – Legacy but still useful for complex gestures.
- TransformableState – Pinch-zoom, rotation, and pan.
- InteractionSource – Track pressed, dragged, focused, hovered states.
Animation & Visuals
- AnimatedVisibility – Smooth show/hide with animation.
- AnimatedContent – Animate content changes.
- animate*AsState – State-based animations.
- updateTransition – Multi-property animated transitions.
- rememberInfiniteTransition – Loops for continuous animation.
- spring – Physics-based animation.
- tween – Time-based animation control.
- keyframes – Complex multi-stage animations.
- graphicsLayer – GPU transforms, rotation, scale, alpha.
- drawWithCache – Precompute drawing for performance.
Drawing & Canvas
- drawBehind – Custom drawing behind a Composable.
- drawWithContent – Override default drawing behavior.
- Canvas – Full control over drawing shapes and paths.
- Path – Complex vector shapes.
- clipPath – Mask Composables into shapes.
- Shadow in graphicsLayer – Custom drop shadows.
- drawCircle, drawLine, drawRect – Low-level drawing.
- PathEffect – Dashed or dotted lines.
- BlendMode – Custom layer blending.
- ColorFilter – Apply color transformations.
State & Reactivity
- derivedStateOf – Efficient derived state computation.
- snapshotFlow – Convert state reads into Flow.
- rememberUpdatedState – Avoid stale lambdas.
- rememberCoroutineScope – Scoped coroutines inside Composables.
- LaunchedEffect – Lifecycle-aware coroutines.
- DisposableEffect – Side effects with cleanup.
- SideEffect – Run code after every composition.
- rememberSaveable – Persist state across configuration changes.
- remember – Store state in composition.
- mutableStateListOf / mutableStateMapOf – Observable collections.
Input & Focus
- FocusRequester – Programmatically request focus.
- focusRequester modifier – Link focus to components.
- focusTarget – Make any Composable focusable.
- LocalFocusManager – Control focus programmatically.
- BringIntoViewRequester – Scroll Composable into view.
- onFocusChanged – Listen to focus state changes.
- onPreviewKeyEvent – Capture keyboard input.
- keyboardActions – Custom actions for text fields.
- keyboardOptions – Control IME and keyboard type.
- textInputService – Low-level text input handling.
Typography & Text
- TextLayoutResult – Get line metrics and text dimensions.
- InlineTextContent – Embed Composables inside Text.
- AnnotatedString – Rich text formatting.
- SpanStyle – Custom text spans.
- ParagraphStyle – Control line height, alignment.
- TextFieldValue – Full control over text fields.
- visualTransformation – Mask/format text input.
- keyboardActions – Handle IME actions.
- SoftWrap – Text wrapping control.
- overflow – Ellipsis, clipping, or fading.
Density & Pixels
- LocalDensity – Convert dp/sp ↔ px precisely.
- Dp / Px conversion – Device-independent drawing.
- LocalLayoutDirection – Handle LTR/RTL layouts.
- with(LocalDensity.current) – Scope density conversions.
- Density.density – Pixels per dp.
- Density.fontScale – Scale text for accessibility.
- LayoutDirection – Detect layout direction.
- IntSize.toDpSize() – Convert size units.
- Offset.toDpOffset() – Convert coordinates.
- Size.toDpSize() – For Canvas measurements.
Lists & Lazy Layouts
- LazyColumn – Virtualized vertical lists.
- LazyRow – Virtualized horizontal lists.
- LazyGrid – Staggered / grid layout.
- LazyListState – Track scroll position.
- LazyListScope – Scope for items and headers.
- item vs items – Single vs multiple items.
- animateItemPlacement() – Smooth reorder animations.
- stickyHeader – Keep header fixed while scrolling.
- rememberLazyListState – Maintain scroll state across recomposition.
- derivedStateOf { firstVisibleItemIndex } – Observe scroll efficiently.
Modifiers & Miscellaneous
- zIndex – Control stacking order.
- shadow – Material elevation shadows.
- border – Outline a Composable.
- paddingFromBaseline – Align text with baseline.
- alpha – Apply transparency.
- clip – Rounded corners, shapes.
- graphicsLayer – Transform layer directly.
- layoutId – Used in ConstraintLayout.
- semantics – Accessibility hints.
- testTag – Assign testing identifiers.
- pointerInteropFilter – Integrate legacy MotionEvents.
Bonus Powerful Gems
- FocusProperties – Customize focus navigation behavior.
- rememberFocusRequester – Persist focus control across recompositions.
- snapToItem – Snap scrolling in lists.
- bringIntoView – Programmatically scroll to child.
- rotationX, rotationY – 3D rotations with graphicsLayer.
- drawWithContent – Custom paint over Composables.
- drawLayer – Legacy low-level layer transformations.
- Modifier.composed – Build reusable custom modifiers.
- rememberUpdatedState – Avoid stale closures in effects.
- LocalInspectionMode – Detect preview mode.
- DisposableEffect(key1) – Lifecycle-aware resource cleanup.
- SnapshotMutationPolicy – Customize state equality checks.
- LaunchedEffect(key) – Tie coroutine to state lifecycle.
- derivedStateOf { } – Efficient recompositions for computed states.
- collectAsState() – Convert Flow/StateFlow to Compose state.
- AnimatedVisibilityScope – Control enter/exit animations.
- Crossfade – Animate between composables with fade.
- graphicsLayer.shadowElevation – Custom elevation shadows.
- rememberSaveable(stateSaver) – Persist complex custom objects.
