MaestroOverlay
MaestroKit provides a suite of SwiftUI components that make integrating rich UI elements seamless. In this chapter, we’ll walk through how to instantiate and use the MaestroOverlay component.
MaestroOverlay
is a struct that provides an overlay view for you to add to your app's view heirarchy. The overlay should be presented either in a .overlay
view modifier, or in a ZStack
above your other views.
The order of events in using the MaestroOverlay goes like this:
- The SDK determines that a MaestroOverlay needs to be shown
- The SDK calls
shouldShowOverlay(buttonSize:overlayType:payload:)
in theMaestroEventDelegate
to tell your app to display an overlay with the givenbuttonSize
. - Your app instances
MaestroOverlay(buttonPosition:overlayType:payload:)
with abuttonPosition
that indicates the position at which the overlay should be disaplayed. Your app should determine the best place for the overlay given thebuttonSize
provided in theshouldShowOverlay()
call. TheoverlayType
andpayload
parameters should be the values you received from the SDK in theshouldShowOverlay(buttonSize:overlayType:payload)
call. - If the user takes no action, or clicks the button, the overlay will call
shouldHideOverlay()
in your app'sMaestroEventDelegate
implementation to let you know the overlay should be dismissed. - Your app should call
didShowOverlay()
anddidHideOverlay()
when those events occur, to keep the SDK apprised of your current use of the MaestroOverlay.
struct MaestroOverlay: View
Parameters
buttonPosition: CGPoint
- An optional CGFloat defining the width of the Overlay.overlayType: OverlayType
- The type of overlay to be shown.payload: MaestroOverlayEvent
- The optional payload for the overlay.
Sample Usage
struct ContentView: View {
var body: some View {
MaestroOverlay(
buttonPosition: CGPoint(x: 1100, y: 100),
overlayType: .fantasy,
payload: nil
)
}
}