I am using the SwiftUI App to build a multi-platform app. However, on macOS, the "Emoji & Symbols" command that normally appears in the "Edit" menu does not show up. Additionally, the typical keyboard shortcut will not open that Emoji picker in my app. Is there a way to enable that command?
Post
Replies
Boosts
Views
Activity
I'm creating a custom SwiftUI view using NSViewRepresentable. However, when the view is used inside a ToolbarItem, makeCoordinator and makeNSView get called twice, leading to glitches due to having an extra instance of the coordinator. If the custom view is moved out of the toolbar, those 2 methods only get called once each as expected.
Here is example code to reproduce:
import SwiftUI
struct ContentView: View {
var body: some View {
Text("Hello, world!")
.padding()
.toolbar(content: {
ToolbarItem {
MyView()
}
})
}
}
struct MyView: NSViewRepresentable {
init() {
print("init")
}
func makeNSView(context: Context) -> NSView {
print("makeNSView")
return NSView()
}
func updateNSView(_ nsView: NSView, context: Context) {
print("updateNSView")
}
func makeCoordinator() -> Coordinator {
print("makeCoordinator")
return Coordinator()
}
typealias NSViewType = NSView
class Coordinator {}
}
Which results in this log:
init
makeCoordinator
makeNSView
updateNSView
makeCoordinator
makeNSView
updateNSView
Does anybody else experience this bug?