diff --git a/macos/ReactTestApp/AppDelegate.swift b/macos/ReactTestApp/AppDelegate.swift index 670542f24..0023a81df 100644 --- a/macos/ReactTestApp/AppDelegate.swift +++ b/macos/ReactTestApp/AppDelegate.swift @@ -102,6 +102,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate { return } + mainWindow?.title = manifest.displayName + let components = manifest.components ?? [] if components.isEmpty { NotificationCenter.default.addObserver( diff --git a/macos/ReactTestApp/Assets.xcassets/ReactMenu.imageset/Contents.json b/macos/ReactTestApp/Assets.xcassets/ReactMenu.imageset/Contents.json deleted file mode 100644 index fdf87e018..000000000 --- a/macos/ReactTestApp/Assets.xcassets/ReactMenu.imageset/Contents.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "images" : [ - { - "idiom" : "universal", - "scale" : "1x" - }, - { - "filename" : "ReactMenu.png", - "idiom" : "universal", - "scale" : "2x" - }, - { - "idiom" : "universal", - "scale" : "3x" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/macos/ReactTestApp/Assets.xcassets/ReactMenu.imageset/ReactMenu.png b/macos/ReactTestApp/Assets.xcassets/ReactMenu.imageset/ReactMenu.png deleted file mode 100644 index 608ee24d8..000000000 Binary files a/macos/ReactTestApp/Assets.xcassets/ReactMenu.imageset/ReactMenu.png and /dev/null differ diff --git a/macos/ReactTestApp/Base.lproj/Main.storyboard b/macos/ReactTestApp/Base.lproj/Main.storyboard index b7d593f66..e7ab9ee5e 100644 --- a/macos/ReactTestApp/Base.lproj/Main.storyboard +++ b/macos/ReactTestApp/Base.lproj/Main.storyboard @@ -1,7 +1,7 @@ - + - + @@ -453,7 +453,7 @@ - + diff --git a/macos/ReactTestApp/ViewController.swift b/macos/ReactTestApp/ViewController.swift index f06817856..b467ece2e 100644 --- a/macos/ReactTestApp/ViewController.swift +++ b/macos/ReactTestApp/ViewController.swift @@ -1,18 +1,28 @@ -import Cocoa +import AppKit final class ViewController: NSViewController { override func viewDidLoad() { super.viewDidLoad() - view.wantsLayer = true - guard let layer = view.layer, - let reactMenuImage = NSImage(named: "ReactMenu") - else { - return - } + let label = Label(text: "Click anywhere to get started or open the React menu in the menu bar") + view.addSubview(label) - layer.contents = reactMenuImage - layer.contentsGravity = .center + NSLayoutConstraint.activate( + NSLayoutConstraint.constraints( + withVisualFormat: "V:|-[label]-|", + options: [], + metrics: nil, + views: ["label": label] + ) + ) + NSLayoutConstraint.activate( + NSLayoutConstraint.constraints( + withVisualFormat: "H:|-[label]-|", + options: [], + metrics: nil, + views: ["label": label] + ) + ) } override var representedObject: Any? { @@ -20,4 +30,54 @@ final class ViewController: NSViewController { // Update the view, if already loaded. } } + + 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) { + guard let reactMenu = NSApplication.shared.mainMenu?.item(withTitle: "React")?.submenu else { + return + } + + popUpContextMenu(reactMenu, with: event, for: view) + } +} + +final class Label: NSTextView { + init(text: String) { + super.init(frame: .zero) + + translatesAutoresizingMaskIntoConstraints = false + string = text + isEditable = false + isSelectable = false + isRichText = false + drawsBackground = false + font = NSFont.messageFont(ofSize: NSFont.systemFontSize) + alignment = .center + } + + override init(frame frameRect: NSRect, textContainer container: NSTextContainer?) { + super.init(frame: frameRect, textContainer: container) + } + + @available(*, unavailable) + required init?(coder _: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func mouseDown(with event: NSEvent) { + NSMenu.popUpReactMenu(with: event, for: self) + } + + override func rightMouseDown(with event: NSEvent) { + NSMenu.popUpReactMenu(with: event, for: self) + } }