This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: cmp-shared-accessibility-semantics-bridge

Compose Multiplatform Shared Accessibility Semantics & Platform-Native A11y Bridge

Enforces deterministic declarative-to-native accessibility mapping across Compose Multiplatform (Android AccessibilityNodeInfo and iOS UIAccessibilityElement/NSAccessibilityElement). Ensures semantics trees are explicitly merged, roles and state descriptions are bound to platform-safe actions, and custom interactive nodes eliminate screen-reader desynchronization and focus trapping across platforms.

Prohibited Anti-Pattern: Ad-Hoc Gesture Handling Without Semantic Node Merging and Platform A11y Action Bridging

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Compose Multiplatform Shared Accessibility Semantics & Platform-Native A11y Bridge - Enforces deterministic declarative-to-native accessibility mapping across Compose Multiplatform (Android AccessibilityNodeInfo and iOS UIAccessibilityElement/NSAccessibilityElement). Ensures semantics trees are explicitly merged, roles and state descriptions are bound to platform-safe actions, and custom interactive nodes eliminate screen-reader desynchronization and focus trapping across platforms.
globs: **/composeApp/**/*.kt, **/commonMain/**/*.kt, **/iosMain/**/*.kt, **/androidMain/**/*.kt
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/cmp-shared-accessibility-semantics-bridge"
---

# Compose Multiplatform Shared Accessibility Semantics & Platform-Native A11y Bridge

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Ad-Hoc Gesture Handling Without Semantic Node Merging and Platform A11y Action Bridging

## System Constraints
You are a Principal Mobile Architect enforcing Compose Multiplatform accessibility invariants. You mandate strict semantic merging, correct mapping of Role and SemanticsPropertyReceiver states (selected, disabled, progress), and explicit platform action bridges to guarantee synchronous updates between Compose's layout tree and native OS assistive tech (TalkBack and iOS VoiceOver).

## Strict Guidelines
- Engineers MUST ALWAYS declare interactive elements using Modifier.semantics(mergeDescendants = true) when grouping compound composables (e.g., custom checkboxes, list items with action badges) to prevent split focus rects in iOS VoiceOver.
- Engineers MUST NOT attach raw Modifier.pointerInput or clickable without explicitly setting semantic Role, onClick label, and stateDescription/toggleableState.
- Components NEVER expose headless non-text decorative iconography to the accessibility tree; Modifier.semantics { invisibleToUser() } or contentDescription = null must be explicitly assigned.
- Custom components exposing swipe, dismiss, or custom interactions MUST declare customActions via SemanticsPropertyReceiver to allow platform-native accessibility rotors and TalkBack local context menus to discover them.
- Dynamic state mutations affecting accessibility (e.g., error banners, real-time counters) MUST emit liveRegion semantics (LiveRegionMode.Polite or LiveRegionMode.Assertive) to prevent screen-reader desynchronization during asynchronous rendering.

## Bad vs Good Implementations
### Interactive List Item with Semantic Action Bridge

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Fails to merge descendants, lacks explicit Role, leaves TalkBack and VoiceOver unable to interpret the component as a single interactive element, and misses contextual action announcements.
```kotlin
@Composable
fun CounterItemBad(
    title: String,
    count: Int,
    onIncrement: () -> Unit,
    modifier: Modifier = Modifier
) {
    // ANTI-PATTERN: Raw pointerInput / clickable without semantic role or merged tree.
    // iOS VoiceOver navigates each child individually, fails to announce state changes,
    // and leaves VoiceOver focus out-of-sync with Compose's internal canvas bounds.
    Row(
        modifier = modifier
            .clickable { onIncrement() }
            .padding(16.dp)
    ) {
        Text(text = title)
        Spacer(Modifier.weight(1f))
        Text(text = "$count")
    }
}
```

#### Production Standard (Correct)
> **Standard**: Merges descendants into a single cohesive native accessibility node, hides redundant child text, declares semantic live region updates, and maps explicit click action labels compatible with iOS VoiceOver and Android TalkBack.
```kotlin
@Composable
fun CounterItemGood(
    title: String,
    count: Int,
    onIncrement: () -> Unit,
    modifier: Modifier = Modifier
) {
    // PRODUCTION FIX: Explicitly merges descendants, declares Role, provides dynamic
    // stateDescription, and binds accessibility actions directly to the platform bridge.
    Row(
        modifier = modifier
            .semantics(mergeDescendants = true) {
                role = Role.Button
                stateDescription = "$count items"
                onClick(label = "Increment $title") {
                    onIncrement()
                    true
                }
                liveRegion = LiveRegionMode.Polite
            }
            .clickable(
                onClickLabel = "Increment",
                role = Role.Button,
                onClick = onIncrement
            )
            .padding(16.dp),
        verticalAlignment = Alignment.CenterVertically
    ) {
        Text(text = title)
        Spacer(Modifier.weight(1f))
        Text(
            text = "$count",
            modifier = Modifier.semantics { invisibleToUser() }
        )
    }
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Compose Multiplatform Shared Accessibility Semantics & Platform-Native A11y Bridge

Compose Multiplatform Shared Accessibility Semantics & Platform-Native A11y Bridge defines an industrial-grade behavioral standard for mobile engineering. Enforces deterministic declarative-to-native accessibility mapping across Compose Multiplatform (Android AccessibilityNodeInfo and iOS UIAccessibilityElement/NSAccessibilityElement). Ensures semantics trees are explicitly merged, roles and state descriptions are bound to platform-safe actions, and custom interactive nodes eliminate screen-reader desynchronization and focus trapping across platforms. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Ad-Hoc Gesture Handling Without Semantic Node Merging and Platform A11y Action Bridging Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftAd-Hoc Gesture Handling Without Semantic Node Merging and Platform A11y Action BridgingCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS declare interactive elements using Modifier.semantics(mergeDescendants = true) when grouping compound composables (e.g., custom checkboxes, list items with action badges) to prevent split focus rects in iOS VoiceOver.

Engineers MUST ALWAYS declare interactive elements using Modifier.semantics(mergeDescendants = true) when grouping compound composables (e.g., custom checkboxes, list items with action badges) to prevent split focus rects in iOS VoiceOver.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT attach raw Modifier.pointerInput or clickable without explicitly setting semantic Role, onClick label, and stateDescription/toggleableState.

Engineers MUST NOT attach raw Modifier.pointerInput or clickable without explicitly setting semantic Role, onClick label, and stateDescription/toggleableState.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Components NEVER expose headless non-text decorative iconography to the accessibility tree

Components NEVER expose headless non-text decorative iconography to the accessibility tree; Modifier.semantics { invisibleToUser() } or contentDescription = null must be explicitly assigned.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Custom components exposing swipe, dismiss, or custom interactions MUST declare customActions via SemanticsPropertyReceiver to allow platform-native accessibility rotors and TalkBack local context menus to discover them.

Custom components exposing swipe, dismiss, or custom interactions MUST declare customActions via SemanticsPropertyReceiver to allow platform-native accessibility rotors and TalkBack local context menus to discover them.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Dynamic state mutations affecting accessibility (e.g., error banners, real-time counters) MUST emit liveRegion semantics (LiveRegionMode.Polite or LiveRegionMode.Assertive) to prevent screen-reader desynchronization during asynchronous rendering.

Dynamic state mutations affecting accessibility (e.g., error banners, real-time counters) MUST emit liveRegion semantics (LiveRegionMode.Polite or LiveRegionMode.Assertive) to prevent screen-reader desynchronization during asynchronous rendering.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Compose Multiplatform Shared Accessibility Semantics & Platform-Native A11y Bridge critical for AI coding assistants?

Enforces deterministic declarative-to-native accessibility mapping across Compose Multiplatform (Android AccessibilityNodeInfo and iOS UIAccessibilityElement/NSAccessibilityElement). Ensures semantics trees are explicitly merged, roles and state descriptions are bound to platform-safe actions, and custom interactive nodes eliminate screen-reader desynchronization and focus trapping across platforms. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Ad-Hoc Gesture Handling Without Semantic Node Merging and Platform A11y Action Bridging) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

Related MOBILE Rules

View all rules →
1 Rule in Stack

Compose