0

I'm making a bridge for react-native-macos. I need NSPanel with the same behaviour as Spotlight. I programmatically created it, but have questions:

  1. Can't make it always on top (also it should work if app is hidden)
  2. There is NSTextField inside the panel. If I try to hide title panel I can't change the field. Looks like it disabled.
  3. What is the best way to display results (like in the spotlight)
private var panel = NSPanel()
private var textField = NSTextField(frame: NSMakeRect(0,0,400,40))

var frame: NSRect = CGRect(x: 0, y: 0, width: 400, height: 40)
frame.size = NSSize(width: 400, height: 60)
panel.setFrame(frame, display: true)
  
let view: NSView = NSView(frame: frame)
    
myTextField.stringValue = "Some text"
myTextField.isEnabled = true
myTextField.font = NSFont.systemFont(ofSize: 28)
    
view.addSubview(myTextField)

panel.contentView?.addSubview(view)

panel.makeKeyAndOrderFront(panel)
panel.center()
Denis
  • 5
  • 2

2 Answers2

0

Make it floating

panel.isFloatingPanel = true           // << this one !!
panel.makeKeyAndOrderFront(panel)
panel.center()
Asperi
  • 123,447
  • 8
  • 131
  • 245
  • I've found solution here https://stackoverflow.com/questions/36205834/allow-an-nswindow-nspanel-to-float-above-full-screen-apps But still have the second problem. Can't change text field if panel doen't have titlebar – Denis Jul 23 '20 at 18:40
  • All application windows removed from screen when application is hidden. You need then not panel, but different kind of application, named application agent and custom window with high window level. Read for example [this article](https://www.appcoda.com/macos-status-bar-apps/) to start. – Asperi Jul 23 '20 at 18:40
0

This works for me

panel.level = .mainMenu
Denis
  • 5
  • 2