Nov*_*ovo 7 macos native reactjs react-native
目前有什么方法可以在 macOS 菜单栏中创建一个在后台运行的 React Native 应用程序吗?
这个问题不是最近出现的,但我发现它在搜索这个主题,并且最近有一个相关更新:随着微软新的桌面工作,这现在是可行的,尽管仍然很棘手。
感谢ospfranco的出色工作。
唯一的方法是编辑您的AppDelegate类并使用 React Native 应用程序中的根视图内容初始化状态按钮标签及其弹出框内容。还可以自定义其大小、外观和栏上的按钮,但只能使用 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"
}
}
Run Code Online (Sandbox Code Playgroud)
参考:
React Native MacOS(微软):https://github.com/microsoft/react-native-macos
示例代码:https ://github.com/ospfranco/react-native-macos-menubar-template
博客文章:https://ospfranco.github.io/post/2020/05/23/how-to-make-a-react-native-menu-bar-app-for-mac-os/
| 归档时间: |
|
| 查看次数: |
1445 次 |
| 最近记录: |