You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug Description, Steps to Reproduce, Crash Logs, Screenshots, etc.
Hello.
First of all, thank you for making a good library.
I found something while using the functions of the library, so I left a post.
I didn't want to keep passing the variable isMenuPresented to the subview with Binding for MenuBarExtraAccess, so I tried to use it wrapped in an ObservableObject.
However, using it in this way caused menubar to close and open abnormally slow (state -> binding is normal)
Below is the code of the way I implemented it.
Is Presented for controlling MenuBarExtraAccess, but is ObservableObject hard to use?
class AppState: ObservableObject {
@Published var isMenuPresented: Bool = false
}
struct MyApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@StateObject var appState = AppState()
MenuBarExtra("ListeningDogApp") {
MenuBarExtraView()
.environmentObject(appDelegate)
.environmentObject(appState)
}
.menuBarExtraStyle(.window)
.menuBarExtraAccess(isPresented: $listengDogAppState.isMenuPresented) { statusItem in // <-- the magic ✨
// access status item or store it in a @State var
}
}
struct PreferencesView: View {
@EnvironmentObject var appDelegate: AppDelegate
@EnvironmentObject var AppState: AppState
@State private var isHovered = false
var body: some View {
Button {
appState.isMenuPresented = false
appDelegate.showMainWindow()
} label: {
HStack {
Text("Preferences...")
Spacer()
}
.frame(height: 30)
}
.buttonStyle(.plain)
}
Bug Description, Steps to Reproduce, Crash Logs, Screenshots, etc.
Hello.
First of all, thank you for making a good library.
I found something while using the functions of the library, so I left a post.
I didn't want to keep passing the variable isMenuPresented to the subview with Binding for MenuBarExtraAccess, so I tried to use it wrapped in an ObservableObject.
However, using it in this way caused menubar to close and open abnormally slow (state -> binding is normal)
Below is the code of the way I implemented it.
Is Presented for controlling MenuBarExtraAccess, but is ObservableObject hard to use?
2023-07-08.10.12.34.mov