Skip to content

feat(macos): migrate menu to SwiftUI App + .commands#2842

Open
Saadnajmi wants to merge 1 commit into
microsoft:trunkfrom
Saadnajmi:saadnajmi/swiftui-macos-menu
Open

feat(macos): migrate menu to SwiftUI App + .commands#2842
Saadnajmi wants to merge 1 commit into
microsoft:trunkfrom
Saadnajmi:saadnajmi/swiftui-macos-menu

Conversation

@Saadnajmi

@Saadnajmi Saadnajmi commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Migrates the macOS test app to the SwiftUI App lifecycle with a declarative .commands menu, following #2836 and #2841 (and mirroring the SwiftUI init template in microsoft/react-native-macos#2948).

SwiftUI provides the standard menus for free, so the makeMainMenu / make*MenuItem code in WindowController.swift is deleted. The dynamic React menu now observes an AppModel, so it re-renders on change — no manual NSMenuItem add/remove bookkeeping.

Changes

  • AppDelegate.swift@main App struct + AppModel; AppDelegate kept via @NSApplicationDelegateAdaptor for RN setup.
  • ReactCommands.swift (new) — CommandMenu("React") with the load actions, remember-last toggle, and components (⌘⇧1–9).
  • ViewController.swift — SwiftUI content host + placeholder.
  • WindowController.swift — deleted.

ENABLE_SINGLE_APP_MODE and multi-app behavior are preserved. The applicationWillFinishLaunching(_:) config-plugin anchor points from #2188 are kept (both [ENABLE_SINGLE_APP_MODE=0] and [=1]).

Verified

Built and launched against react-native-macos 0.81. Menu bar: Apple · Example · Edit · View · React · Window · Help (no File menu, matching SwiftUI apps). The React menu lists the components with ⌘⇧1/2 shortcuts; selecting one presents it. swiftformat --lint and swiftlint --strict pass.

@Saadnajmi

Copy link
Copy Markdown
Collaborator Author
image

@Saadnajmi Saadnajmi force-pushed the saadnajmi/swiftui-macos-menu branch 2 times, most recently from 5dfb2e1 to 7a0d41e Compare July 7, 2026 23:30
@Saadnajmi Saadnajmi marked this pull request as ready for review July 7, 2026 23:31
@Saadnajmi Saadnajmi requested review from JasonVMo and tido64 as code owners July 7, 2026 23:31
@Saadnajmi Saadnajmi marked this pull request as draft July 7, 2026 23:31
@Saadnajmi Saadnajmi marked this pull request as ready for review July 8, 2026 06:46
Replace the programmatic AppKit menu bar (added in microsoft#2836) with the SwiftUI
App lifecycle. SwiftUI provides the standard App/File/Edit/View/Window/Help
menus for free, so the ~320 lines of makeMainMenu/make*MenuItem in
WindowController.swift are deleted.

The dynamic "React" menu is now declarative: ReactCommands renders a
CommandMenu("React") driven by an observable AppModel. Publishing
components/componentsEnabled/rememberLastComponent rebuilds the menu, so the
manual NSMenuItem add/remove bookkeeping is gone. An AppDelegate is kept via
@NSApplicationDelegateAdaptor for RN setup and lifecycle notifications.

- AppDelegate.swift: @main App struct + adaptor + AppModel
- ReactCommands.swift: dynamic React menu (Cmd-Shift-1..9 component shortcuts)
- ViewController.swift: SwiftUI content hosting + placeholder
- WindowController.swift: deleted
- project.pbxproj / pack.test.mts: swap WindowController.swift for ReactCommands.swift

Both ENABLE_SINGLE_APP_MODE and multi-app behavior are preserved.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Saadnajmi Saadnajmi force-pushed the saadnajmi/swiftui-macos-menu branch from 7a0d41e to a24dfe7 Compare July 10, 2026 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant