Skip to content
Merged
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: 2 additions & 0 deletions macos/ReactTestApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
return
}

mainWindow?.title = manifest.displayName

let components = manifest.components ?? []
if components.isEmpty {
NotificationCenter.default.addObserver(
Expand Down

This file was deleted.

Binary file not shown.
6 changes: 3 additions & 3 deletions macos/ReactTestApp/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="19529" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="19529"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="20037"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -453,7 +453,7 @@
<scene sceneID="R2V-B0-nI4">
<objects>
<windowController id="B8D-0N-5wS" sceneMemberID="viewController">
<window key="window" identifier="MainWindow" title="Open React Menu to Get Started" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="MainWindow" animationBehavior="default" id="IQv-IB-iLA">
<window key="window" identifier="MainWindow" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="MainWindow" animationBehavior="default" id="IQv-IB-iLA">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="480" height="270"/>
Expand Down
78 changes: 69 additions & 9 deletions macos/ReactTestApp/ViewController.swift
Original file line number Diff line number Diff line change
@@ -1,23 +1,83 @@
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? {
didSet {
// 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)
}
}