Skip to content

feat(event): add key press APIs and keyboard shortcut bindings - #1067

Merged
Kyle-Ye merged 11 commits into
mainfrom
feature/key_press
Sep 10, 2026
Merged

feat(event): add key press APIs and keyboard shortcut bindings#1067
Kyle-Ye merged 11 commits into
mainfrom
feature/key_press

Conversation

@Kyle-Ye

@Kyle-Ye Kyle-Ye commented Sep 9, 2026

Copy link
Copy Markdown
Member

Summary

  • Add KeyPress and onKeyPress APIs with handler registration, deprecated aliases, and parameterized coverage.
  • Implement keyboard shortcut values, View and Scene modifiers, picker option traits, and shortcut binding preferences.
  • Add lazy platform item list generation and group ViewThatFits child items under a parent item.
  • Document the keyboard APIs and consolidate KeyEquivalent with KeyboardShortcut.

Validation: Whitespace checks passed. Tests and builds were not rerun.

@github-actions github-actions Bot added area: event-gesture Events, gestures, tracing, or interaction plumbing. area: tests Test suites, UI tests, fixtures, snapshots, and test support code. type: feature New API, behavior, platform support, or user-facing capability. area: app-scene App, scene, window, commands, storage, and lifecycle APIs. labels Sep 9, 2026
@augmentcode

augmentcode Bot commented Sep 9, 2026

Copy link
Copy Markdown

PR Risk Analyzer Agent 🛡️

👀 Human review needed

Justification

This is a large feature PR (+1339 / −197 across 14 files, 8 commits) that introduces substantial new public API surface and modifies core framework infrastructure, so it falls outside any automatic low-risk classification.

  • New public API: KeyPress, KeyPress.Phases, KeyPress.Result, the full onKeyPress(...) family (plus @_spi deprecated keysIn: / charactersIn: aliases), KeyboardShortcut, KeyboardShortcut.Localization, KeyEquivalent, and the View / Scene keyboardShortcut(...) modifiers. New public/stable API shape and availability annotations warrant human design review.
  • Core infrastructure touched: new EnvironmentValues keys (keyPressHandlers, keyboardShortcut, sceneKeyboardShortcuts), _GraphInputs accessors, CachedEnvironment.ID entries, a host-preference writer, and a StatefulRule (BindKeyboardShortcutItems) that manipulates attribute-graph subgraphs (PlatformItemListGenerator).
  • Behavioral refactors: PlatformItemList.Item gains many new fields; the previously-unimplemented ViewThatFits representable now builds a grouped child item list; KeyEquivalent/KeyboardShortcut are consolidated and the prior TODO copies removed; TransformEvent is relocated into its own file; Scene.transformPreference is now nonisolated.
  • Verification gap: the PR description states "Tests and builds were not rerun." Correctness of the new attribute-graph rules and event dispatch is not confirmed in the description; rely on CI plus reviewer verification.

Reviewed commit 709227f

@augmentcode

augmentcode Bot commented Sep 9, 2026

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: Adds initial keyboard input and shortcut API surface intended to match SwiftUI.

Changes:

  • Introduces KeyPress, phase/result types, and View.onKeyPress overloads.
  • Stores key-press handler registrations in environment values and adds focused-key event test coverage.
  • Consolidates KeyEquivalent with a new KeyboardShortcut implementation.
  • Adds view and scene keyboardShortcut modifiers, localization options, and picker traits.
  • Adds shortcut-binding preference types and lazy platform-item-list generation for labels.
  • Extends platform item metadata and groups ViewThatFits child items under a parent item.
  • Moves TransformEvent into its own source file and updates scene preference isolation.
Technical notes: Keyboard APIs are unavailable on watchOS (and shortcut APIs on tvOS); validation reported whitespace checks only, with builds and tests not rerun.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

phases: KeyPress.Phases,
action: @escaping (KeyPress) -> KeyPress.Result
) -> some View {
modifier(KeyPressModifier(handler: .init(subject: subject, phases: phases, action: action)))

@augmentcode augmentcode Bot Sep 9, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sources/OpenSwiftUI/Event/InputEvent/Keyboard/KeyPressModifier.swift:129onKeyPress only appends a KeyPress.Handler to EnvironmentValues; no responder or ForwardedEventDispatcher reads keyPressHandlers, while the UIKit responder sends KeyEvent values to a manager with no KeyEvent dispatcher. As a result, registrations through every overload are never matched or invoked at runtime.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

action: @escaping () -> Void,
label: () -> V
) -> some View where V: View {
modifier(KeyboardShortcutBindingBehavior(action: action, label: label()))

@augmentcode augmentcode Bot Sep 9, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sources/OpenSwiftUI/Event/InputEvent/Keyboard/KeyboardShortcut.swift:543keyboardShortcutBindingBehavior has no callers, and no host requests or consumes KeyboardShortcutBindingsKey (the current Button implementation is also an EmptyView). Therefore the public keyboardShortcut modifier only sets environment/trait state and never produces an executable shortcut binding.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

@github-actions github-actions Bot added the area: view View APIs, modifiers, AnyView, ForEach, DynamicView, and related behavior. label Sep 9, 2026
@tuist

tuist Bot commented Sep 9, 2026

Copy link
Copy Markdown

🛠️ Tuist Run Report 🛠️

Tests 🧪

Scheme Status Cache hit rate Tests Skipped Ran Commit
OpenSwiftUI 0 % 1197 0 1197 1c3839e9f

Builds 🔨

Scheme Status Duration Commit
OpenSwiftUI 36.4s 1c3839e9f

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep Code Review Agent🐛

Review completed with 4 suggestions.

Reviewed commit: b58ceeb

Comment thread Tests/OpenSwiftUITests/Event/InputEvent/KeyPressTests.swift
Comment thread Sources/OpenSwiftUI/Event/InputEvent/Keyboard/KeyboardShortcut.swift Outdated
Add a fileprivate event conversion initializer for KeyPress tests and apply picker shortcut traits directly.
@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 19.80198% with 162 lines in your changes missing coverage. Please review.
✅ Project coverage is 29.98%. Comparing base (5fe50c7) to head (cdcd1f3).

Files with missing lines Patch % Lines
...I/Event/InputEvent/Keyboard/KeyboardShortcut.swift 4.12% 93 Missing ⚠️
...n/PlatformItemList/PlatformItemListGenerator.swift 0.00% 33 Missing ⚠️
...ntegration/PlatformItemList/PlatformItemList.swift 0.00% 13 Missing ⚠️
...urces/OpenSwiftUI/Event/Event/TransformEvent.swift 0.00% 11 Missing ⚠️
.../Picker/KeyboardShortcutPickerOptionTraitKey.swift 0.00% 7 Missing ⚠️
...ration/PlatformItemList/PlatformItemListFlag.swift 0.00% 3 Missing ⚠️
...I/Event/InputEvent/Keyboard/KeyPressModifier.swift 94.73% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1067      +/-   ##
==========================================
+ Coverage   29.92%   29.98%   +0.05%     
==========================================
  Files         787      790       +3     
  Lines       62259    62423     +164     
==========================================
+ Hits        18631    18717      +86     
- Misses      43628    43706      +78     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Kyle-Ye
Kyle-Ye merged commit 217da04 into main Sep 10, 2026
6 checks passed
@Kyle-Ye
Kyle-Ye deleted the feature/key_press branch September 10, 2026 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: app-scene App, scene, window, commands, storage, and lifecycle APIs. area: event-gesture Events, gestures, tracing, or interaction plumbing. area: tests Test suites, UI tests, fixtures, snapshots, and test support code. area: view View APIs, modifiers, AnyView, ForEach, DynamicView, and related behavior. type: feature New API, behavior, platform support, or user-facing capability.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant