compose-slot-api-pattern

Convert primitive Jetpack Compose component parameters into composable slot parameters.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/soygabimoreno/Los-ANDROIDES --skill compose-slot-api-pattern
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: compose-slot-api-pattern
Source: https://github.com/soygabimoreno/Los-ANDROIDES/tree/main/.agents/skills/compose-slot-api-pattern
Command: npx skills add https://github.com/soygabimoreno/Los-ANDROIDES --skill compose-slot-api-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It prevents reusable Jetpack Compose components from becoming hard to extend when visual content differs across call sites and parameters start turning into an ever-growing list of primitives and booleans.

Core Features & Use Cases

  • Replace primitive content params with composable slots: delegate variable UI regions to caller-provided @Composable lambdas so the component defines structure while the caller defines content.
  • Use scope receivers when the slot needs layout APIs: declare slots as @Composable RowScope.() -> Unit (or BoxScope/ColumnScope) when the slot is rendered inside that layout so callers can use weight, alignment, and scope-specific modifiers.
  • Model optional UI as nullable slots: prefer (@Composable () -> Unit)? = null over empty-lambda defaults to clearly distinguish “absent” from “present but empty,” enabling the component to skip spacing and containers.
  • Centralize common defaults in XxxDefaults: move reusable default slot content into a nearby Defaults object so the main component API stays clean and call sites remain concise.
  • Use-case example: when designing a reusable settings/list row that might show an icon, a badge, a switch, or custom trailing content depending on the screen, slot the leading/headline/supporting/trailing regions instead of enumerating variants and flags.

Quick Start

Refactor your reusable Compose component so every caller-controlled visual region is exposed as a dedicated @Composable slot, using nullable slots for optional regions and a scope receiver only when the slot’s layout context needs it.

Frequently Asked Questions about compose-slot-api-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make Jetpack Compose components reusable without adding boolean variant flags?

To make Jetpack Compose components reusable without boolean flags, replace primitive content parameters with composable slot lambdas. This delegates variable UI regions to the caller while the component defines the stable layout structure.

What is the slot API pattern in Jetpack Compose UI architecture?

The slot API pattern in Jetpack Compose UI architecture is a design approach where composable lambdas act as parameters representing variable visual regions. Callers provide the content while the component maintains the layout structure.

How do I use scope receivers like RowScope with composable slot parameters?

To use scope receivers with composable slot parameters, declare slots as @Composable RowScope.() -> Unit when rendered inside a Row layout. This allows callers to access layout-specific APIs like weight and alignment.

Should optional composable slots in Kotlin use nullable lambdas or empty defaults?

Optional composable slots in Kotlin should use nullable lambdas with null defaults, like (@Composable () -> Unit)? = null. This distinguishes absent content from present but empty, allowing components to skip rendering spacing and containers.

Where should I place default slot implementations for Compose components?

Default slot implementations for Compose components should be centralized in a nearby XxxDefaults object. This keeps the main component API clean and ensures call sites remain concise when using common default content.