Post

Replies

Boosts

Views

Activity

SwiftUI NSViewRepresentable methods called twice when in the Toolbar
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?
0
0
895
Sep ’21
SwiftUI NSViewRepresentable methods called twice when in the Toolbar
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?
Replies
0
Boosts
0
Views
895
Activity
Sep ’21
macOS Emoji picker does not work in SwiftUI App
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?
Replies
2
Boosts
0
Views
1.6k
Activity
Dec ’22