目前有什么方法可以创建一个在 macOS 菜单栏中后台运行的 React Native 应用程序吗?
最佳答案
这个问题不是最近提出的,但我发现它在搜索这个主题,并且最近有一个相关更新:通过 Microsoft 的新桌面工作,这现在是可行的,尽管仍然很棘手。
致谢ospfranco为了伟大的工作。
<小时/>唯一的方法是编辑 AppDelegate
类,并使用 React Native 应用程序中的 Root View 内容初始化状态按钮标签及其弹出内容。还可以自定义其大小、外观和栏上的按钮,但只能使用 Swift 代码。
func applicationDidFinishLaunching(_ aNotification: Notification) {
let jsCodeLocation: URL
jsCodeLocation = RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index", fallbackResource:nil)
let rootView = RCTRootView(bundleURL: jsCodeLocation, moduleName: "tempomat", initialProperties: nil, launchOptions: nil)
let rootViewController = NSViewController()
rootViewController.view = rootView
popover = NSPopover()
popover.contentSize = NSSize(width: 700, height: 800)
popover.animates = true
popover.behavior = .transient
popover.contentViewController = rootViewController
statusBarItem = NSStatusBar.system.statusItem(withLength: CGFloat(60))
if let button = self.statusBarItem.button {
button.action = #selector(togglePopover(_:))
button.title = "Tempomat"
}
}
引用文献:
关于macos - React Native macOS 菜单栏应用程序可以吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43824547/