Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion macos/ReactTestApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ extension AppDelegate {
return viewController
}

let viewController = NSViewController(nibName: nil, bundle: nil)
let viewController = HostingViewController(nibName: nil, bundle: nil)
viewController.title = title
viewController.view = host.view(
moduleName: component.appKey,
Expand Down
19 changes: 16 additions & 3 deletions macos/ReactTestApp/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,29 @@ final class ViewController: NSViewController {
)
}

#endif // !ENABLE_SINGLE_APP_MODE

override func mouseDown(with event: NSEvent) {
NSMenu.popUpReactMenu(with: event, for: view)
}

override func rightMouseDown(with event: NSEvent) {
NSMenu.popUpReactMenu(with: event, for: view)
}

#endif // !ENABLE_SINGLE_APP_MODE
}

#if !ENABLE_SINGLE_APP_MODE
// Hosts a React Native root view. The Fabric root view does not implement
// `menuForEvent:`, so right-click events propagate up the responder chain to
// this controller, which presents the React menu as a context menu.
final class HostingViewController: NSViewController {
override func mouseDown(with event: NSEvent) {
NSMenu.popUpReactMenu(with: event, for: view)
}

override func rightMouseDown(with event: NSEvent) {
NSMenu.popUpReactMenu(with: event, for: view)
}
}

extension NSMenu {
static func popUpReactMenu(with event: NSEvent, for view: NSView) {
Expand All @@ -56,6 +67,8 @@ extension NSMenu {
}
}

#if !ENABLE_SINGLE_APP_MODE

final class Label: NSTextView {
init(text: String) {
super.init(frame: .zero)
Expand Down