focus-engine

Manage keyboard and directional focus behavior across SwiftUI and UIKit on Apple platforms.

Updated May 10, 2026
One-click install
npx skills add https://github.com/FelixRauch/medat-figuren --skill focus-engine-felixrauch
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: focus-engine
Source: https://github.com/FelixRauch/medat-figuren/tree/main/.agents/skills/focus-engine
Command: npx skills add https://github.com/FelixRauch/medat-figuren --skill focus-engine-felixrauch

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Focus breaks user flow on multi-platform Apple apps when keyboard, directional navigation, and focus restoration are inconsistent, leaving users unsure where input will land next.

Core Features & Use Cases

  • SwiftUI focus management with @FocusState, .focused, .defaultFocus, and focusable custom controls via .focusable(interactions:).
  • Scene-aware focused state using focused values like focusedSceneValue for menus/commands/toolbars that must act on the currently focused content.
  • Platform-specific focus navigation including macOS/tvOS focusSection() guidance for uneven layouts and UIKit routing with UIFocusGuide.
  • Focus restoration after transient UI so dismissing sheets/popovers overlays returns focus to a stable, logical element.
  • Debugging and anti-pattern prevention using patterns and references to diagnose why items don’t receive focus and to avoid common focus regressions.

Quick Start

Use @FocusState with an explicit default focus target, restore focus in .onDisappear after sheets/popovers, and apply focusSection() on macOS/tvOS when directional navigation would otherwise skip or jump to the wrong group.

Frequently Asked Questions about focus-engine

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

FAQPage Schema
How do I manage focus restoration in SwiftUI after dismissing a sheet or popover?

Focus restoration in SwiftUI requires returning focus to a stable element after dismissing sheets or popovers. You should use @FocusState to bind focus, explicitly restore focus in .onDisappear, and set a default focus target to ensure predictable keyboard navigation.

Why does directional focus skip UI elements in my tvOS uneven layouts?

Directional focus skips elements in uneven layouts when guidance is missing. Apply focusSection() on macOS and tvOS to group focusable areas, ensuring directional navigation lands on the correct target instead of jumping unpredictably across the interface.

What's the best way to route focus across mixed SwiftUI and UIKit views?

Routing focus across SwiftUI and UIKit requires combining @FocusState with UIFocusGuide for UIKit sections. Use focusable(interactions:) for custom controls and apply focusSection() to maintain consistent keyboard and directional navigation across both frameworks.

How do I use focusedSceneValue for scene-aware commands in SwiftUI?

FocusedSceneValue provides scene-aware focused state for SwiftUI menus and toolbars. Use focused values to bind commands to the currently focused content, ensuring menu actions and toolbar buttons operate on the correct active scene element.

How do I debug why my SwiftUI custom control is not receiving focus?

Debugging focus issues involves checking if your custom control uses .focusable(interactions:) correctly and verifying @FocusState bindings. Focus anti-patterns, such as missing default focus targets or conflicting focusable semantics, often prevent elements from receiving focus.

Does UIFocusGuide work for focus routing on iOS and iPadOS?

UIFocusGuide works for focus routing on iOS and iPadOS, although it is most commonly associated with tvOS. It provides an invisible region that redirects focus to a target view, helping navigate complex UIKit layouts where direct directional paths are missing.