This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: compose-ios-surface-cadisplaylink-sync

Compose Multiplatform iOS Native Surface Synchronization Invariant

Prevents main-thread micro-stutter, frame hitching, and visual tearing by strictly synchronizing Skiko rendering frames with CADisplayLink and iOS CATransaction state transitions. Eliminates out-of-phase Metal surface presentation when embedding UIKit views or coordinating animations between Compose and UIKit layer hierarchies. Mandates explicit frame-pacing hooks and transaction boundaries for all cross-platform surface interactions.

Prohibited Anti-Pattern: Asynchronous Unsynchronized Skiko Metal Frame Submission Across UIKit Transitions

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Compose Multiplatform iOS Native Surface Synchronization Invariant - Prevents main-thread micro-stutter, frame hitching, and visual tearing by strictly synchronizing Skiko rendering frames with CADisplayLink and iOS CATransaction state transitions. Eliminates out-of-phase Metal surface presentation when embedding UIKit views or coordinating animations between Compose and UIKit layer hierarchies. Mandates explicit frame-pacing hooks and transaction boundaries for all cross-platform surface interactions.
globs: **/iosMain/**/*.kt, **/*.ios.kt, **/iosApp/**/*.swift, **/iosApp/**/*.m
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/compose-ios-surface-cadisplaylink-sync"
---

# Compose Multiplatform iOS Native Surface Synchronization Invariant

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Asynchronous Unsynchronized Skiko Metal Frame Submission Across UIKit Transitions

## System Constraints
You are a Principal Engineer enforcing the Compose Multiplatform iOS Native Surface Synchronization Invariant. Mandate invariants that eliminate UI hitches, frame drops, and visual tearing during Skiko rendering and UIKit layer synchronization. You must enforce explicit CADisplayLink frame pacing, disable implicit CoreAnimation actions during interop layout passes, and guarantee atomic CATransaction commits between native views and Skiko Metal surfaces.

## Strict Guidelines
- Engineers MUST ALWAYS wrap native UIKit layer mutations occurring within or alongside Compose rendering passes in an explicit CATransaction block with actions disabled (CATransaction.setDisableActions(true)).
- Engineers MUST NOT invoke asynchronous Skiko surface redraw requests outside of CADisplayLink VSYNC callbacks or active UI event cycles.
- Engineers MUST configure CADisplayLink targetTimestamp and preferredFrameRateRange to respect ProMotion displays (120Hz dynamic refresh) and synchronize Skiko's draw loop with the display hardware.
- Code SHOULD enforce atomic layout transitions when resizing ComposeUIViewController host surfaces by invoking CATransaction.flush() and coordinating redraw cycles before UIKit layer presentation.
- Components NEVER bridge UIKitView or UIKitViewController without synchronizing frame bounds within the same run-loop turn as the Skiko Metal layer layout pass.

## Bad vs Good Implementations
### Synchronizing Skiko Rendering and UIKit Layer Bounds with CADisplayLink and CATransaction

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Mutating view frames without disabling implicit CATransaction actions causes a mismatch between UIKit's layout animation and the underlying Skiko Metal surface. Firing redraws via DispatchQueue.main.async decouples rendering from CADisplayLink VSYNC, resulting in visible tearing, frame drops, and jitter on 120Hz ProMotion screens.
```swift
// BAD: Mutating UIKit frame and scheduling Skiko rendering asynchronously without transaction boundaries
final class ComposeSurfaceBridge: UIViewController {
    private var displayLink: CADisplayLink?
    private var composeView: UIView!

    func updateBounds(newFrame: CGRect) {
        // Implicit CA animations trigger mismatch between Metal buffer and UIKit frame
        composeView.frame = newFrame
        
        // Unsynchronized async rendering schedules out-of-order Metal commit
        DispatchQueue.main.async {
            self.triggerSkikoRender()
        }
    }

    private func triggerSkikoRender() {
        // Unthrottled render call out-of-sync with hardware VSYNC phase
    }
}
```

#### Production Standard (Correct)
> **Standard**: Disabling implicit CATransaction actions ensures UIKit layers and Skiko Metal buffers update atomically. Integrating CADisplayLink with explicit ProMotion support (CAFrameRateRange) and .common runloop mode prevents dropped frames and micro-stutter during scrolling and interactive transitions.
```swift
// GOOD: Deterministic CATransaction encapsulation synchronized with CADisplayLink VSYNC
final class ComposeSurfaceBridge: UIViewController {
    private var displayLink: CADisplayLink?
    private var composeView: UIView!

    func updateBounds(newFrame: CGRect) {
        CATransaction.begin()
        CATransaction.setDisableActions(true)
        
        composeView.frame = newFrame
        composeView.layoutIfNeeded()
        
        // Force synchronous Metal surface resizing before transaction commit
        CATransaction.setCompletionBlock {
            // Optional post-transition synchronization hook
        }
        
        CATransaction.commit()
    }

    func setupDisplayLink() {
        displayLink = CADisplayLink(target: self, selector: #selector(onDisplayLinkTick))
        // Support ProMotion dynamic refresh rates
        displayLink?.preferredFrameRateRange = CAFrameRateRange(minimum: 60, maximum: 120, preferred: 120)
        displayLink?.add(to: .main, forMode: .common)
    }

    @objc private func onDisplayLinkTick(link: CADisplayLink) {
        CATransaction.begin()
        CATransaction.setDisableActions(true)
        // Drive frame dispatch precisely within the hardware VSYNC window
        link.targetTimestamp
        CATransaction.commit()
    }
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Compose Multiplatform iOS Native Surface Synchronization Invariant

Compose Multiplatform iOS Native Surface Synchronization Invariant defines an industrial-grade behavioral standard for mobile engineering. Prevents main-thread micro-stutter, frame hitching, and visual tearing by strictly synchronizing Skiko rendering frames with CADisplayLink and iOS CATransaction state transitions. Eliminates out-of-phase Metal surface presentation when embedding UIKit views or coordinating animations between Compose and UIKit layer hierarchies. Mandates explicit frame-pacing hooks and transaction boundaries for all cross-platform surface interactions. 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: Asynchronous Unsynchronized Skiko Metal Frame Submission Across UIKit Transitions 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 DriftAsynchronous Unsynchronized Skiko Metal Frame Submission Across UIKit TransitionsCritical
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 wrap native UIKit layer mutations occurring within or alongside Compose rendering passes in an explicit CATransaction block with actions disabled (CATransaction.setDisableActions(true)).

Engineers MUST ALWAYS wrap native UIKit layer mutations occurring within or alongside Compose rendering passes in an explicit CATransaction block with actions disabled (CATransaction.setDisableActions(true)).

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 invoke asynchronous Skiko surface redraw requests outside of CADisplayLink VSYNC callbacks or active UI event cycles.

Engineers MUST NOT invoke asynchronous Skiko surface redraw requests outside of CADisplayLink VSYNC callbacks or active UI event cycles.

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

Engineers MUST configure CADisplayLink targetTimestamp and preferredFrameRateRange to respect ProMotion displays (120Hz dynamic refresh) and synchronize Skiko's draw loop with the display hardware.

Engineers MUST configure CADisplayLink targetTimestamp and preferredFrameRateRange to respect ProMotion displays (120Hz dynamic refresh) and synchronize Skiko's draw loop with the display hardware.

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

Code SHOULD enforce atomic layout transitions when resizing ComposeUIViewController host surfaces by invoking CATransaction.flush() and coordinating redraw cycles before UIKit layer presentation.

Code SHOULD enforce atomic layout transitions when resizing ComposeUIViewController host surfaces by invoking CATransaction.flush() and coordinating redraw cycles before UIKit layer presentation.

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

Components NEVER bridge UIKitView or UIKitViewController without synchronizing frame bounds within the same run-loop turn as the Skiko Metal layer layout pass.

Components NEVER bridge UIKitView or UIKitViewController without synchronizing frame bounds within the same run-loop turn as the Skiko Metal layer layout pass.

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 iOS Native Surface Synchronization Invariant critical for AI coding assistants?

Prevents main-thread micro-stutter, frame hitching, and visual tearing by strictly synchronizing Skiko rendering frames with CADisplayLink and iOS CATransaction state transitions. Eliminates out-of-phase Metal surface presentation when embedding UIKit views or coordinating animations between Compose and UIKit layer hierarchies. Mandates explicit frame-pacing hooks and transaction boundaries for all cross-platform surface interactions. 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 (Asynchronous Unsynchronized Skiko Metal Frame Submission Across UIKit Transitions) 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