Programmatic Panel Switching (shouldShowPanelType
)
To give host apps a thread‑safe, public API for switching panels at runtime, we’ve introduced a new method:
public func shouldShowPanelType(panel: MaestroPanelType) async
Follow these steps to wire it through the SDK:
1. Expose on MaestroManager
(Root Actor)
In your SDK’s root actor, add:
public func shouldShowPanelType(panel: MaestroPanelType) {
Task { @MainActor in
if let vm = await getMaestroEventViewModel() {
vm.changePanel(to: panel)
}
}
}
Why? This provides a simple, thread‑safe entry point for clients to switch panels instantly:
await MaestroManager.shared.shouldShowPanelType(panel: .bets)
2. Conform the Singleton to the ViewModel Delegate
Extend the MaestroManagerViewModelDelegate
protocol implementation:
public func shouldShowPanelType(panel: MaestroPanelType) {
Task { @MainActor in
maestroEventViewModel?.changePanel(to: panel)
}
}
Why?
Marking it public
satisfies the delegate requirement and ensures the internal pathway (facade → delegate → view model) compiles and routes correctly.
3. Forward to the SwiftUI ViewModel
In MaestroEventViewModel
, implement the panel‑switch logic:
func changePanel(to panelType: MaestroPanelType) {
currentPanel = panelType // @Published drives the UI swap
}
Why?
Updating @Published var currentPanel
on the @MainActor
causes SwiftUI’s PanelManagerView
to automatically fade out the old panel and fade in the new one, just like a user tapping a tab.
Usage Example
await MaestroManager.shared.shouldShowPanelType(panel: .bets)
Note: Ensure your UI observes
MaestroEventViewModel.currentPanel
so that panel changes take effect immediately.