Ordering Modifier Chains logo

Ordering Modifier Chains

Community
skydoves
ordering-modifier-chains

Use this skill to diagnose and fix Jetpack Compose Modifier ordering bugs — wrong paint region for background, wrong click area for clickable, wrong clipping for clip, wrong measurement for padding/size, surprising graphicsLayer scope. Covers the wrap-the-next-modifier mental model, the canonical pitfalls (padding vs background, clickable placement, clip before background, graphicsLayer placement), and why hoisting an entire Modifier chain via remember { Modifier.… } is rarely a real perf win because Compose already interns identical chains. Use when the developer asks "why does the click area extend past the visible button", "why is my background painted in the wrong place", "does Modifier order matter", "should I cache my Modifier chain", or reviews a diff that reorders modifiers.

Overview

Publisherskydoves
Repositorycompose-performance-skills
Skill nameordering-modifier-chains
Stars
515
Forks
19
Bundled files
Instructions only
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by skydoves on GitHub. Read the source before you install it.

Installation

Install the Ordering Modifier Chains AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/skydoves/compose-performance-skills/tree/main/modifiers/ordering-modifier-chains
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/skydoves/compose-performance-skills.git /tmp/compose-performance-skills
mkdir -p .claude/skills
cp -r /tmp/compose-performance-skills/modifiers/ordering-modifier-chains .claude/skills/ordering-modifier-chains
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Ordering Modifier Chains in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Ordering Modifier Chains on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Ordering Modifier Chains is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Ordering Modifier Chains — Why padding(8.dp).background(Red) ≠ background(Red).padding(8.dp)

Modifier order matters because each modifier wraps the next as a function. Modifier.padding(8.dp).background(Red) shrinks constraints first, so the background paints INSIDE the padded region — the surrounding 8 dp margin has no red. Conversely, Modifier.background(Red).padding(8.dp) paints red across the parent's full bounds before insetting the content. Wrong order is the most common Compose UI bug after missing keys. This skill teaches Claude how to read a chain top-to-bottom and reorder it correctly.

When to use this skill

  • The developer asks "why does the click area extend past the visible button?", "why is my ripple bouncing on the wrong shape?", "why is the background painted in the wrong area?", or "does Modifier order matter?".
  • A code review shows a chain like Modifier.padding(...).clickable { }, Modifier.background(...).clip(...), or Modifier.alpha(state.value).graphicsLayer { }.
  • A button's tap target leaks into the surrounding padding, or the corner radius is not honored on the background.
  • A clip on a parent is failing to mask a child draw, or graphicsLayer { alpha = 0.5f } is half-applying to siblings.
  • The developer is considering hoisting a Modifier chain via remember { Modifier.… } "for perf".

When NOT to use this skill

  • The chain order is correct and the symptom is elsewhere (state read in the wrong phase, missing keys in a lazy layout). Diagnose with ../../recomposition/deferring-state-reads/SKILL.md or ../../lists/optimizing-lazy-layouts/SKILL.md first.
  • The custom modifier itself is the problem (composed { } legacy, missing diff) → see ../migrating-to-modifier-node/SKILL.md.
  • The question is whether to make a custom modifier — this skill assumes you already have a chain of built-ins and need to order them right.

Prerequisites

  • Basic familiarity with Modifier composition vocabulary (padding, background, clip, clickable, graphicsLayer).
  • Compose UI any supported version — modifier ordering semantics have been stable since 1.0.
  • A real-device, release build for any final perf claim about hoisting (skydoves hot take #5: debug builds lie).

Workflow

  • 1. Identify the symptom precisely. Match it to one of: paint region wrong, click / pointer area wrong, ripple bounds wrong, clip area wrong, padding measurement wrong, graphicsLayer scope wrong. Each maps to a specific reorder.

  • 2. Read the chain top-to-bottom — each modifier's effect applies to everything BELOW it. Treat the chain as nested function calls: Modifier.a().b().c() means "a wraps (b wraps (c))". The top modifier is the outermost wrapper; the bottom modifier is closest to the content.

  • 3. Apply the canonical reorder for the symptom. The patterns below cover the four most common cases (padding vs background, clickable placement, clip before background, graphicsLayer scope).

  • 4. Pay special attention to these modifiers — order is observable, not stylistic:

    • clickable — the pointer hit area is the bounds AT ITS POSITION in the chain. Anything ABOVE it (outer) is included; anything BELOW it (inner) is not.
    • clip — clips everything BELOW it (inner). Anything ABOVE it is unclipped.
    • background — paints across the bounds AT ITS POSITION in the chain.
    • padding — subtracts from the available space passed to everything BELOW it.
    • graphicsLayer — wraps everything BELOW it in a render layer (alpha, transforms, clipping all apply to the subtree under it).
  • 5. Decide on touch-target accessibility. Material's 48dp minimum touch target is achieved by placing clickable ABOVE the visual padding so the padded area is tappable. The trade-off: ripples will also fire in the padding. For visual-area-only clicks, clickable goes BELOW padding.

  • 6. Resist hoisting a Modifier chain via remember "for perf". Compose already interns structurally-equal Modifier chains internally; remember { Modifier.fillMaxWidth().padding(16.dp) } is a micro-optimization that rarely shows up in a profile. MUST NOT add such a remember without first proving with a FrameTimingMetric benchmark that the unhoisted chain measurably regresses. See ../../lists/optimizing-lazy-layouts/SKILL.md for the broader allocation-in-items lambda discussion.

Patterns

Pattern: background OUTSIDE vs INSIDE padding

kotlin
// WRONG (when the intent is "padded box with red fill")
Box(Modifier.padding(8.dp).background(Color.Red))
// WRONG because: padding is applied first; background then paints across the inner (padded) bounds — the result is a smaller red region, with no red in the padded margin. If the design intent was "red card with 8dp internal padding", red is on the wrong side of the padding.
kotlin
// RIGHT — red fills the box; content is inset by 8dp.
Box(Modifier.background(Color.Red).padding(8.dp)) { /* content */ }

The reverse is also a valid composition — but only when the developer specifically wants the red to NOT extend into the surrounding padding (e.g. a small inner badge). Default to background → padding for "card with internal padding".

Pattern: clickable ABOVE vs BELOW padding (touch target vs visual area)

kotlin
// WRONG (when the click should fire only on the visible icon)
Box(Modifier.padding(16.dp).clickable { onTap() })
// WRONG because: clickable's hit region is its position in the chain — and at this position, the bounds INCLUDE the padding. Taps in the padding fire onTap and ripple bounces past the visible icon.
kotlin
// RIGHT — click only fires on the visible content area.
Box(Modifier.clickable { onTap() }.padding(16.dp))
kotlin
// RIGHT — accessibility 48dp touch target: extend the tap area into the padding intentionally.
Box(
    Modifier
        .padding(8.dp)            // outer spacing
        .clickable { onTap() }    // tap fires across the next size step
        .padding(16.dp)           // visual padding inside the tap area
)

The 48dp minimum touch target (Material) is achieved by deliberately placing clickable so that it sits OUTSIDE the visual padding but INSIDE any external spacing. Pick whichever matches the design intent — neither order is "more correct"; they describe different products.

Pattern: clip BEFORE vs AFTER background

kotlin
// WRONG (rounded card with red fill)
Box(Modifier.background(Color.Red).clip(RoundedCornerShape(8.dp)))
// WRONG because: background paints first across square bounds; clip then applies to children only. The red rectangle is unclipped — corners stay square.
kotlin
// RIGHT — clip wraps the background, so the red is rounded.
Box(Modifier.clip(RoundedCornerShape(8.dp)).background(Color.Red))

For modifiers that combine clip + background semantics, Modifier.background(color = ..., shape = ...) does both in one node and avoids the ordering question:

kotlin
// RIGHT — single modifier handles shape clipping and fill atomically.
Box(Modifier.background(Color.Red, RoundedCornerShape(8.dp)))

Pattern: graphicsLayer wraps everything BELOW it

kotlin
// RIGHT — alpha applies to the entire subtree (background + content).
Box(
    Modifier
        .graphicsLayer { alpha = 0.5f }
        .background(Color.Red)
        .padding(8.dp)
) { Text("Half-faded card") }
kotlin
// WRONG — alpha only fades the content; background is fully opaque.
Box(
    Modifier
        .background(Color.Red)
        .padding(8.dp)
        .graphicsLayer { alpha = 0.5f }
) { Text("Surprising opacity") }
// WRONG because: graphicsLayer wraps only what's below it; the background painted above is not in its layer.

This is the most common "why is my fade weird" bug after wrong-phase animation reads. Place graphicsLayer at (or near) the top of the chain when the intent is "fade this entire visual unit".

Pattern: clickable inside graphicsLayer (the hit-test surprise)

kotlin
// RIGHT — graphicsLayer { } wraps clickable; ripple is captured into the layer.
Box(
    Modifier
        .graphicsLayer { alpha = 0.9f }
        .clickable { onTap() }
        .padding(16.dp)
)

graphicsLayer does NOT change hit-test geometry — clickable hit-tests against its own position in the chain, regardless of whether a graphicsLayer is wrapping it. If the graphicsLayer applies a transform (translation, scale, rotation), the hit test follows the laid-out (pre-transform) bounds; Modifier.pointerInput { } with explicit hit testing is required for transformed hit-tests. Cross-reference ../../recomposition/deferring-state-reads/SKILL.md for the wider phase discussion.

Pattern: hoisting a Modifier chain — usually not a win

kotlin
// OK but rarely necessary
@Composable
fun SnackList(snacks: ImmutableList<Snack>) {
    val rowModifier = remember { Modifier.fillMaxWidth().padding(16.dp) }
    LazyColumn {
        items(snacks, key = { it.id }) { snack -> SnackRow(snack, rowModifier) }
    }
}
kotlin
// Equally fine in practice
@Composable
fun SnackList(snacks: ImmutableList<Snack>) {
    LazyColumn {
        items(snacks, key = { it.id }) { snack ->
            SnackRow(snack, Modifier.fillMaxWidth().padding(16.dp))
        }
    }
}

Compose interns structurally-equal Modifier chains. The two snippets above produce the same equals-compatible chain at every item position. Hoisting via remember saves at most a single allocation per item per recomposition — measurable in synthetic micro-benchmarks, invisible in FrameTimingMetric on real surfaces. MUST NOT add the remember line "for perf" without a FrameTimingMetric regression to point at. See ../migrating-to-modifier-node/SKILL.md for the much bigger win — fixing a Modifier.composed { } factory.

Pattern: padding then size — the unmeasurable order

kotlin
// Both compile; both are valid; they mean different things.
Box(Modifier.size(100.dp).padding(8.dp))   // 100dp box, 8dp inner padding → 84dp content area
Box(Modifier.padding(8.dp).size(100.dp))   // 100dp content area, 8dp outer margin → 116dp total

size constrains the bounds at its position in the chain; padding subtracts from the available space passed to everything below. Read top-to-bottom: the order describes the layout, it does not "do the same thing in a different order".

Mandatory rules

  • MUST read modifier chains top-to-bottom and reason about each modifier as a wrapper around everything below it.
  • MUST place clickable AFTER padding (padding then clickable, where clickable is below padding in the chain) when the click should be the visible area only. Place clickable BEFORE padding when the design requires the padded area to be tappable (Material 48dp touch target).
  • MUST place clip BEFORE background to clip the background paint. Or use Modifier.background(color, shape) to avoid the ordering question entirely.
  • MUST place graphicsLayer near the top of the chain when its transforms / alpha must apply to the whole visual unit (including the background).
  • MUST NOT hoist a Modifier chain via remember { Modifier.… } solely "for perf" without a FrameTimingMetric regression to point at — Compose already interns identical chains and the saved allocation rarely shows up in a profile.
  • MUST NOT add a Modifier.composed { } factory to "fix" an ordering issue. If a custom modifier needs to be in a specific position, it can be a Modifier.Node directly. See ../migrating-to-modifier-node/SKILL.md.
  • PREFERRED: explicit padding → clickable → padding sandwich for tappable items where accessibility (48dp minimum) is the goal — outer spacing, the clickable area sized to include the visual padding, and inner padding for the content.
  • PREFERRED: Modifier.background(color = ..., shape = ...) over the clip(shape).background(color) pair when both are needed.

Verification

  • The painted region (background, border) matches the design intent — no surprise red bleed past the corner radius, no red inside an unintended padding margin.
  • The click / ripple area matches the design intent — taps in the padding fire (or do not fire) deliberately, not by accident.
  • clip masks every layer below it; clipped corners look right on every theme.
  • graphicsLayer { alpha = ... } (or scaleX, rotationZ, etc.) affects the intended subtree only; background and content fade together when expected.
  • For any hoisted Modifier chain, a FrameTimingMetric macrobenchmark in release + R8 + real device shows a measurable improvement vs the unhoisted version. If not, drop the remember.
  • No Modifier.composed { } was added to work around a chain-order question (re-grep the module).

References

Frequently asked questions

What does the Ordering Modifier Chains AI skill do?

Use this skill to diagnose and fix Jetpack Compose Modifier ordering bugs — wrong paint region for background, wrong click area for clickable, wrong clipping for clip, wrong measurement for padding/size, surprising graphicsLayer scope. Covers the wrap-the-next-modifier mental model, the canonical pitfalls (padding vs background, clickable placement, clip before background, graphicsLayer placement), and why hoisting an entire Modifier chain via remember { Modifier.… } is rarely a real perf win because Compose already interns identical chains. Use when the developer asks "why does the click a...

Why use Ordering Modifier Chains on TypingMind?

Because you install it once and use it with any model. Ordering Modifier Chains is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Ordering Modifier Chains in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/skydoves/compose-performance-skills/tree/main/modifiers/ordering-modifier-chains. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Ordering Modifier Chains?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Ordering Modifier Chains?

As many as you like. As long as a model supports skills, you can use Ordering Modifier Chains with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Ordering Modifier Chains AI skill free?

Yes. It is published on GitHub by skydoves under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇