This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: capacitor7-predictive-back-window-insets-sync

Capacitor 7 Predictive Back & Android 15 Window Insets Synchronization

Enforces edge-to-edge layout compliance and predictive back gesture synchronization under Capacitor 7 and Android 15 (API 35). Prevents viewport clipping behind system bars, touch event coordinate offsets, and abrupt app terminations by unifying native WindowInsetsCompat with CSS safe-area variables and client-side router navigation stacks.

Prohibited Anti-Pattern: Hardcoded Viewport Offsets and Uncoordinated Native-to-Web Navigation Stacks Causing UI Clipping and Gesture Collisions

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Capacitor 7 Predictive Back & Android 15 Window Insets Synchronization - Enforces edge-to-edge layout compliance and predictive back gesture synchronization under Capacitor 7 and Android 15 (API 35). Prevents viewport clipping behind system bars, touch event coordinate offsets, and abrupt app terminations by unifying native WindowInsetsCompat with CSS safe-area variables and client-side router navigation stacks.
globs: src/**/*.{ts,tsx,vue,svelte,html,css}, capacitor.config.ts, android/app/src/main/res/values/styles.xml, android/app/src/main/java/**/MainActivity.java
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/capacitor7-predictive-back-window-insets-sync"
---

# Capacitor 7 Predictive Back & Android 15 Window Insets Synchronization

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Hardcoded Viewport Offsets and Uncoordinated Native-to-Web Navigation Stacks Causing UI Clipping and Gesture Collisions

## System Constraints
You are a Principal Mobile Architect enforcing Capacitor 7 edge-to-edge and predictive back gesture invariants. Android 15 enforces edge-to-edge rendering by default, deprecating fitsSystemWindows in WebViews and introducing predictive back gesture animations. You must ensure all layouts use dynamic CSS environment variables (viewport-fit=cover), eliminate hardcoded status/nav bar compensations, and cleanly bind native back button dispatching to client-side single-page app (SPA) history stacks.

## Strict Guidelines
- Engineers MUST ALWAYS declare `<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">` in `index.html` to allow the WebView to consume full native window insets.
- Engineers MUST ALWAYS style structural containers (headers, footers, toolbars, fixed action buttons) using CSS `env(safe-area-inset-top)`, `env(safe-area-inset-bottom)`, `env(safe-area-inset-left)`, and `env(safe-area-inset-right)` with sensible fallback values.
- Engineers MUST NOT hardcode status bar or navigation bar pixel heights (e.g., `padding-top: 24px` or `padding-bottom: 48px`) in stylesheets or script calculations.
- Engineers MUST register a prioritized native back-button listener via `@capacitor/app` (`App.addListener('backButton', callback)`) to coordinate SPA route pops before delegating to root activity exit.
- Engineers MUST NOT invoke `App.exitApp()` unconditionally on back-gesture triggers; verify router depth (`window.history.length > 1` or stateful router depth) and allow predictive back gestures to resolve cleanly.
- Components NEVER apply double-inset padding by wrapping already-padded layout primitives within nested safe-area utilities.

## Bad vs Good Implementations
### Predictive Back & Inset Coordination in TypeScript

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Hardcoded 24px status bar padding breaks on modern edge-to-edge displays (camera cutouts, dynamic islands, foldable hinges) and Android 15 edge-to-edge enforcement. Immediately calling App.exitApp() breaks Android 15 predictive back gesture transitions and bypasses SPA route history, crashing user workflows.
```typescript
import { App } from '@capacitor/app';

// ANTI-PATTERN: Hardcoded paddings and uncoordinated exit handling
export function setupAppNavigation(router: { back: () => void; canGoBack: () => boolean }) {
  // Hardcoded offset assuming legacy Android status bar
  const header = document.querySelector('header');
  if (header) {
    header.style.paddingTop = '24px';
  }

  // Directly hooking back button without checking canGoBack causes instant exit or broken gestures
  App.addListener('backButton', () => {
    App.exitApp();
  });
}
```

#### Production Standard (Correct)
> **Standard**: Relies on CSS safe-area environment variables for structural alignment under Android 15 edge-to-edge rendering, while coordinating the native back button event hierarchy with the SPA router before delegating to `App.exitApp()`.
```typescript
import { App, BackButtonListenerEvent } from '@capacitor/app';
import type { PluginListenerHandle } from '@capacitor/core';

interface NavController {
  canGoBack: () => boolean;
  back: () => void;
}

export async function registerPredictiveBackSync(router: NavController): Promise<PluginListenerHandle> {
  // Insets are handled in CSS via env(safe-area-inset-*); zero inline layout hacks required.
  return await App.addListener('backButton', (event: BackButtonListenerEvent) => {
    if (router.canGoBack()) {
      // Synchronize internal SPA navigation with native gesture event
      router.back();
    } else if (event.canGoBack) {
      // Native browser/webview stack fallback
      window.history.back();
    } else {
      // Exit application only when at root of SPA and native navigation stacks
      App.exitApp();
    }
  });
}
```

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: Capacitor 7 Predictive Back & Android 15 Window Insets Synchronization

Capacitor 7 Predictive Back & Android 15 Window Insets Synchronization defines an industrial-grade behavioral standard for mobile engineering. Enforces edge-to-edge layout compliance and predictive back gesture synchronization under Capacitor 7 and Android 15 (API 35). Prevents viewport clipping behind system bars, touch event coordinate offsets, and abrupt app terminations by unifying native WindowInsetsCompat with CSS safe-area variables and client-side router navigation stacks. 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: Hardcoded Viewport Offsets and Uncoordinated Native-to-Web Navigation Stacks Causing UI Clipping and Gesture Collisions 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 DriftHardcoded Viewport Offsets and Uncoordinated Native-to-Web Navigation Stacks Causing UI Clipping and Gesture CollisionsCritical
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 `<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">` in `index.html` to allow the WebView to consume full native window insets.

Engineers MUST ALWAYS declare `<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">` in `index.html` to allow the WebView to consume full native window insets.

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 ALWAYS style structural containers (headers, footers, toolbars, fixed action buttons) using CSS `env(safe-area-inset-top)`, `env(safe-area-inset-bottom)`, `env(safe-area-inset-left)`, and `env(safe-area-inset-right)` with sensible fallback values.

Engineers MUST ALWAYS style structural containers (headers, footers, toolbars, fixed action buttons) using CSS `env(safe-area-inset-top)`, `env(safe-area-inset-bottom)`, `env(safe-area-inset-left)`, and `env(safe-area-inset-right)` with sensible fallback values.

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 NOT hardcode status bar or navigation bar pixel heights (e.g., `padding-top

Engineers MUST NOT hardcode status bar or navigation bar pixel heights (e.g., `padding-top: 24px` or `padding-bottom: 48px`) in stylesheets or script calculations.

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

Engineers MUST register a prioritized native back-button listener via `@capacitor/app` (`App.addListener('backButton', callback)`) to coordinate SPA route pops before delegating to root activity exit.

Engineers MUST register a prioritized native back-button listener via `@capacitor/app` (`App.addListener('backButton', callback)`) to coordinate SPA route pops before delegating to root activity exit.

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

Engineers MUST NOT invoke `App.exitApp()` unconditionally on back-gesture triggers

Engineers MUST NOT invoke `App.exitApp()` unconditionally on back-gesture triggers; verify router depth (`window.history.length > 1` or stateful router depth) and allow predictive back gestures to resolve cleanly.

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.
6

Components NEVER apply double-inset padding by wrapping already-padded layout primitives within nested safe-area utilities.

Components NEVER apply double-inset padding by wrapping already-padded layout primitives within nested safe-area utilities.

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 Capacitor 7 Predictive Back & Android 15 Window Insets Synchronization critical for AI coding assistants?

Enforces edge-to-edge layout compliance and predictive back gesture synchronization under Capacitor 7 and Android 15 (API 35). Prevents viewport clipping behind system bars, touch event coordinate offsets, and abrupt app terminations by unifying native WindowInsetsCompat with CSS safe-area variables and client-side router navigation stacks. 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 (Hardcoded Viewport Offsets and Uncoordinated Native-to-Web Navigation Stacks Causing UI Clipping and Gesture Collisions) 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

Capacitor