### Full Example App Configuration and Views Source: https://github.com/mijick/popups/blob/main/_autodocs/quick-start.md This snippet shows the complete setup for an example application using the Popups library. It includes global configuration, main app structure, content view with buttons to present different popups, and definitions for Alert, Notification, and Sheet popups. ```swift @main struct ExampleApp: App { var body: some Scene { WindowGroup { ContentView() .registerPopups { config .vertical { $0.cornerRadius(20) } .center { $0.backgroundColor(.white) } } } } } struct ContentView: View { var body: some View { VStack(spacing: 16) { Button("Alert") { Task { await AlertPopup().present() } } Button("Notification") { Task { await NotificationPopup(message: "Success!").dismissAfter(2).present() } } Button("Sheet") { Task { await SheetPopup().present() } } } .padding() } } struct AlertPopup: CenterPopup { var body: some View { VStack { Text("Hello").font(.headline) Button("OK") { Task { await PopupStack.dismissLastPopup() } } } .padding() } } struct NotificationPopup: TopPopup { let message: String var body: some View { Text(message) } } struct SheetPopup: BottomPopup { var body: some View { VStack { Text("Sheet Content") Button("Close") { Task { await PopupStack.dismissLastPopup() } } } .padding() } } ``` -------------------------------- ### Swift Code Example Source: https://github.com/mijick/popups/blob/main/_autodocs/FILE_LISTING.md Illustrates a typical Swift code example found within the documentation files. These examples are realistic and runnable. ```swift import SwiftUI struct ContentView: View { var body: some View { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") } .padding() } } ``` -------------------------------- ### Complete Popup Scene Delegate Example Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/popup-scene-delegate.md A comprehensive example integrating AppDelegate, CustomPopupSceneDelegate, and SwiftUI views for presenting popups. ```swift import SwiftUI import MijickPopups @main struct MyApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate var body: some Scene { WindowGroup { ContentView() } } } // MARK: - AppDelegate class AppDelegate: NSObject, UIApplicationDelegate { func application( _ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions ) -> UISceneConfiguration { let sceneConfig = UISceneConfiguration(name: nil, sessionRole: connectingSceneSession.role) sceneConfig.delegateClass = CustomPopupSceneDelegate.self return sceneConfig } } // MARK: - Custom PopupSceneDelegate class CustomPopupSceneDelegate: PopupSceneDelegate { override init() { super.init() configBuilder = { config in config .vertical { vertical in vertical .enableDragGesture(true) .tapOutsideToDismissPopup(true) .cornerRadius(32) .popupBottomPadding(16) } .center { center in center .tapOutsideToDismissPopup(false) .backgroundColor(.white) .overlayColor(.black.opacity(0.4)) } } } override func sceneStoppedBeingFirstResponder() { print("Popup scene stopped being first responder") } } // MARK: - Views struct ContentView: View { var body: some View { NavigationStack { VStack { Button("Show Popup") { Task { await MyPopup().present() } } } .navigationTitle("Home") } } } struct MyPopup: CenterPopup { var body: some View { VStack(spacing: 16) { Text("Hello from PopupSceneDelegate") .font(.headline) Button("Dismiss") { Task { await PopupStack.dismissLastPopup() } } } .padding() } } ``` -------------------------------- ### BottomSheetPopup Example Source: https://github.com/mijick/popups/blob/main/_autodocs/types.md An example of how to implement a BottomSheetPopup using BottomPopupConfig to customize its appearance and behavior. ```swift struct BottomSheetPopup: BottomPopup { func configurePopup(config: BottomPopupConfig) -> BottomPopupConfig { config .cornerRadius(20) .popupBottomPadding(16) .heightMode(.auto) .dragDetents([.fraction(0.5), .large]) .enableDragGesture(true) } var body: some View { VStack { RoundedRectangle(cornerRadius: 3) .fill(Color.gray) .frame(width: 40, height: 5) .padding(.top) Text("Bottom Sheet Content") Spacer() } .padding() } } ``` -------------------------------- ### Example CenterAlertPopup Configuration Source: https://github.com/mijick/popups/blob/main/_autodocs/types.md Demonstrates how to create and configure a CenterAlertPopup using the provided configuration methods. This example sets corner radius, padding, colors, and tap-to-dismiss behavior. ```swift struct CenterAlertPopup: CenterPopup { let title: String let message: String func configurePopup(config: CenterPopupConfig) -> CenterPopupConfig { config .cornerRadius(20) .popupHorizontalPadding(20) .backgroundColor(.white) .overlayColor(.black.opacity(0.4)) .tapOutsideToDismissPopup(true) } var body: some View { VStack(spacing: 16) { Text(title).font(.headline) Text(message) HStack { Button("Cancel") { Task { await PopupStack.dismissLastPopup() } } Button("OK") { Task { await PopupStack.dismissLastPopup() } } } } .padding() } } ``` -------------------------------- ### App Setup with Popup Registration Source: https://github.com/mijick/popups/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt This snippet shows the basic setup for a SwiftUI application to integrate popup functionality by calling the .registerPopups() modifier on the WindowGroup. ```swift @main struct App: App { var body: some Scene { WindowGroup { ContentView() .registerPopups() } } } ``` -------------------------------- ### Present a Popup Source: https://github.com/mijick/popups/blob/main/_autodocs/quick-start.md Use the `.present()` method on a popup instance within a `Task` to display it. This example shows how to present the `GreetingPopup`. ```swift Button("Show Popup") { Task { await GreetingPopup().present() } } ``` -------------------------------- ### Registering Popups with Configuration Source: https://github.com/mijick/popups/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt Illustrates how to configure global popup settings during application setup, including specific configurations for vertical and center popups. ```swift .registerPopups { config in config .vertical { $0.cornerRadius(20) } .center { $0.backgroundColor(.white) } } ``` -------------------------------- ### Multi-Window Setup with PopupStackID Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/popup-stack-id.md Demonstrates how to set up multiple windows and register unique PopupStackIDs for each. This allows for targeted popup presentation and dismissal in different window contexts. ```swift @main struct MyApp: App { var body: some Scene { Window("Main", id: "main") { MainView() .registerPopups(id: .mainWindow) } Window("Detail", id: "detail") { DetailView() .registerPopups(id: .detailWindow) } } } extension PopupStackID { static let mainWindow: Self = .init(rawValue: "main-window") static let detailWindow: Self = .init(rawValue: "detail-window") } struct MainView: View { var body: some View { Button("Show Popup") { Task { await MyPopup().present(popupStackID: .mainWindow) } } } } struct DetailView: View { var body: some View { Button("Show Popup") { Task { await MyPopup().present(popupStackID: .detailWindow) } } } } ``` -------------------------------- ### Register MijickPopups Framework Source: https://github.com/mijick/popups/blob/main/_autodocs/quick-start.md Call `registerPopups()` in your app's root view to set up the framework. This is a one-time setup required for all popups. ```swift @main struct MyApp: App { var body: some Scene { WindowGroup { ContentView() .registerPopups() } } } ``` -------------------------------- ### Configure Popup Example Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/popup-protocol.md Customize popup settings like corner radius, background color, and dismissal behavior. This method is called before the popup is presented. ```swift struct MyPopup: CenterPopup { func configurePopup(config: CenterPopupConfig) -> CenterPopupConfig { config .cornerRadius(44) .backgroundColor(.blue) .tapOutsideToDismissPopup(true) } var body: some View { Text("Hello!") } } ``` -------------------------------- ### TopPopup Example: NotificationPopup Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/popup-protocol.md An example implementation of a TopPopup for displaying notifications. It configures corner radius, top padding, and auto height mode. ```swift struct NotificationPopup: TopPopup { let message: String func configurePopup(config: TopPopupConfig) -> TopPopupConfig { config .cornerRadius(12) .popupTopPadding(16) .heightMode(.auto) } var body: some View { HStack { Image(systemName: "bell.fill") Text(message) } .padding() } } ``` -------------------------------- ### On Focus Callback Example Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/popup-protocol.md Execute actions when a popup becomes the active view. Useful for animations or analytics when the popup gains focus. ```swift struct MyPopup: TopPopup { func onFocus() { print("Popup is now active") // Perform setup or animation } var body: some View { Text("Active popup") } } ``` -------------------------------- ### Register MijickPopups Framework Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/view-registration.md This is the primary setup method for MijickPopups. Call it on a view in your application hierarchy where you want popups to be displayed. The framework will overlay a popup container on top of your view. Popups are presented on top of the registered view. ```swift func registerPopups( id: PopupStackID = .shared, configBuilder: @escaping (GlobalConfigContainer) -> GlobalConfigContainer = { $0 } ) -> some View ``` -------------------------------- ### CenterPopup Example: AlertPopup Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/popup-protocol.md An example implementation of a CenterPopup for displaying alerts. It configures corner radius, background color, and disables dismissing by tapping outside. ```swift struct AlertPopup: CenterPopup { let title: String let message: String func configurePopup(config: CenterPopupConfig) -> CenterPopupConfig { config .cornerRadius(24) .backgroundColor(.white) .tapOutsideToDismissPopup(false) } var body: some View { VStack(spacing: 16) { Text(title).font(.headline) Text(message) Button("OK") { Task { await PopupStack.dismissLastPopup() } } } .padding() } } ``` -------------------------------- ### Create Custom PopupStackID Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/popup-stack-id.md Example of creating a custom PopupStackID instance with a specific raw string value. ```swift let customStack = PopupStackID(rawValue: "my-custom-stack") ``` -------------------------------- ### SwiftUI Loading Popup Source: https://github.com/mijick/popups/blob/main/_autodocs/quick-start.md Implements a simple loading popup with a progress view and a 'Loading...' message. Includes an example of how to present, perform work, and dismiss the popup. ```swift struct LoadingPopup: CenterPopup { var body: some View { VStack(spacing: 12) { ProgressView() Text("Loading...") } .padding() } } // Use it Task { await LoadingPopup().present() // Do work try? await Task.sleep(nanoseconds: 2_000_000_000) // Dismiss await PopupStack.dismissPopup(LoadingPopup.self) } ``` -------------------------------- ### Define a Basic Popup Source: https://github.com/mijick/popups/blob/main/_autodocs/quick-start.md Create a struct conforming to the `Popup` protocol (or its subtypes) to define the content and behavior of your popup. This example shows a simple greeting popup. ```swift struct GreetingPopup: CenterPopup { var body: some View { VStack { Text("Hello!") .font(.headline) Button("OK") { Task { await PopupStack.dismissLastPopup() } } } .padding() } } ``` -------------------------------- ### Type-Safe Configuration for Center Popups Source: https://github.com/mijick/popups/blob/main/_autodocs/configuration.md Example of type-safe configuration for a center popup using generics. Demonstrates available and unavailable configuration methods for `CenterPopupConfig`. ```swift // This is type-safe - LocalConfigCenter only accepts center-specific methods struct CenterPopup: CenterPopup { func configurePopup(config: CenterPopupConfig) -> CenterPopupConfig { config .popupHorizontalPadding(20) // ✓ Available on CenterPopupConfig // .dragDetents([]) // ✗ Would not compile - not on CenterPopupConfig // .heightMode(.auto) // ✗ Would not compile - not on CenterPopupConfig } var body: some View { Text("Hello") } } ``` -------------------------------- ### Popup HeightMode Usage Examples Source: https://github.com/mijick/popups/blob/main/_autodocs/types.md Demonstrates how to configure popups with different HeightMode settings. The `.auto` mode adapts to content, `.large` uses a fixed screen height, and `.fullscreen` fills the entire screen. ```swift struct MyPopup: BottomPopup { func configurePopup(config: BottomPopupConfig) -> BottomPopupConfig { config.heightMode(.auto) // Default, adapts to content } var body: some View { VStack { Text("Short content") .padding() } } } ``` ```swift struct TallPopup: BottomPopup { func configurePopup(config: BottomPopupConfig) -> BottomPopupConfig { config.heightMode(.large) // Fixed height } var body: some View { VStack { Text("Lots of content...") } .frame(height: 2000) } } ``` ```swift struct FullscreenPopup: TopPopup { func configurePopup(config: TopPopupConfig) -> TopPopupConfig { config.heightMode(.fullscreen) // Full screen } var body: some View { ZStack { Color.blue.ignoresSafeArea() Text("Fullscreen content") } } } ``` -------------------------------- ### Create a Top Popup (Notification) Source: https://github.com/mijick/popups/blob/main/_autodocs/quick-start.md Define a `TopPopup` for displaying notifications. This example includes custom background color, corner radius, and padding. ```swift struct NotificationPopup: TopPopup { let message: String func configurePopup(config: TopPopupConfig) -> TopPopupConfig { config .cornerRadius(12) .popupTopPadding(16) } var body: some View { HStack { Image(systemName: "checkmark.circle.fill") Text(message) } .padding() .background(Color.green) .cornerRadius(12) } } ``` -------------------------------- ### Chaining Popup Configuration Methods Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/popup-methods.md Chain multiple configuration methods to customize a popup's behavior before presenting it. This example shows setting a custom ID, environment object, dismissal delay, and keyboard dismissal behavior. ```swift Task { await MyPopup() .setCustomID("my-popup") .setEnvironmentObject(viewModel) .dismissAfter(3.0) .dismissKeyboardOnDismissal(false) .present(popupStackID: .shared) } ``` -------------------------------- ### Global Popup Configuration Source: https://github.com/mijick/popups/blob/main/_autodocs/README.md Set default configurations for all popups during registration. This example shows how to configure vertical and center popups with specific properties like corner radius and drag gestures. ```swift .registerPopups { config in config .vertical { vertical in vertical .cornerRadius(20) .enableDragGesture(true) .dragDetents([.fraction(0.5), .large]) } .center { center in center .cornerRadius(16) .backgroundColor(.white) .tapOutsideToDismissPopup(false) } } ``` -------------------------------- ### BottomPopup Example: ActionSheetPopup Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/popup-protocol.md An example implementation of a BottomPopup for action sheets. It configures corner radius, bottom padding, auto height, and drag detents. ```swift struct ActionSheetPopup: BottomPopup { let onEdit: () -> Void let onDelete: () -> Void func configurePopup(config: BottomPopupConfig) -> BottomPopupConfig { config .cornerRadius(24) .popupBottomPadding(16) .heightMode(.auto) .dragDetents([.fraction(0.5), .large]) } var body: some View { VStack(spacing: 12) { Button("Edit") { onEdit() } Button("Delete", role: .destructive) { onDelete() } Button("Cancel", role: .cancel) { } } .padding() } } ``` -------------------------------- ### Essential Setup for SwiftUI App Source: https://github.com/mijick/popups/blob/main/_autodocs/README.md Integrate the .registerPopups() modifier in your App struct to enable popup functionality. ```swift @main struct App: App { var body: some Scene { WindowGroup { ContentView() .registerPopups() } } } ``` -------------------------------- ### Create a Simple Alert Popup Source: https://github.com/mijick/popups/blob/main/_autodocs/INDEX.md Define a simple alert popup struct conforming to CenterPopup and present it. This example demonstrates basic popup creation and presentation. ```swift struct AlertPopup: CenterPopup { var body: some View { Text("Alert") } } Task { await AlertPopup().present() } ``` -------------------------------- ### Per-Popup Configuration Source: https://github.com/mijick/popups/blob/main/_autodocs/README.md Override global configurations for individual popups. This example demonstrates configuring a `CenterPopup` with a custom corner radius and background color. ```swift struct MyPopup: CenterPopup { func configurePopup(config: CenterPopupConfig) -> CenterPopupConfig { config .cornerRadius(24) .backgroundColor(.blue) } var body: some View { Text("Hello") } } ``` -------------------------------- ### On Dismiss Callback Example Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/popup-protocol.md Perform cleanup or trigger actions when a popup is dismissed. This method is called when the popup is removed from the stack. ```swift struct MyPopup: BottomPopup { @State var text: String = "" func onDismiss() { print("Popup dismissed with text: \(text)") // Perform cleanup } var body: some View { TextField("Enter text", text: $text) } } ``` -------------------------------- ### Configure Bottom Popup Appearance Source: https://github.com/mijick/popups/wiki/Popup-Declaration Optionally implement the 'configurePopup' method to customize the appearance of a BottomPopup. This example sets horizontal padding, bottom padding, and corner radius. ```swift struct BottomCustomPopup: BottomPopup { var body: some View { HStack(spacing: 0) { Text("Hello World") Spacer() Button(action: { Task { await dismissLastPopup() }}) { Text("Dismiss") } } .padding(.vertical, 20) .padding(.leading, 24) .padding(.trailing, 16) } func configurePopup(config: BottomPopupConfig) -> BottomPopupConfig { config .horizontalPadding(20) .bottomPadding(42) .cornerRadius(16) } } ``` -------------------------------- ### Configurable Popup Registration Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/view-registration.md Customize popup behavior and appearance by providing a configuration closure during registration. This example shows how to configure vertical and center popups with specific gestures, dismissals, corner radius, padding, and background color. ```swift @main struct MyApp: App { var body: some Scene { WindowGroup { ContentView() .registerPopups { config in config .vertical { vertical in vertical .enableDragGesture(true) .tapOutsideToDismissPopup(true) .cornerRadius(32) .popupBottomPadding(20) } .center { center in center .tapOutsideToDismissPopup(false) .backgroundColor(.white) .popupHorizontalPadding(16) } } } } } ``` -------------------------------- ### Create a Bottom Popup (Sheet) Source: https://github.com/mijick/popups/blob/main/_autodocs/quick-start.md Define a `BottomPopup` to create sheet-like interfaces. This example configures height, drag detents, and enables the drag gesture. ```swift struct BottomSheetPopup: BottomPopup { let items: [String] func configurePopup(config: BottomPopupConfig) -> BottomPopupConfig { config .heightMode(.auto) .dragDetents([.fraction(0.5), .large]) .enableDragGesture(true) } var body: some View { VStack(spacing: 12) { RoundedRectangle(cornerRadius: 3) .fill(Color.gray) .frame(width: 40, height: 5) ForEach(items, id: \.self) { item in Button(item) { } } } .padding() } } ``` -------------------------------- ### Type-Safe Configuration for Vertical Popups Source: https://github.com/mijick/popups/blob/main/_autodocs/configuration.md Example of type-safe configuration for a vertical popup using generics. Shows available configuration methods for `BottomPopupConfig`, including inherited ones. ```swift // Vertical popups have more options struct BottomPopup: BottomPopup { func configurePopup(config: BottomPopupConfig) -> BottomPopupConfig { config .popupBottomPadding(16) // ✓ Available .dragDetents([.large]) // ✓ Available .heightMode(.auto) // ✓ Available // .popupHorizontalPadding(16) // ✓ Available (inherited from Vertical) } var body: some View { Text("Hello") } } ``` -------------------------------- ### Implement OnFocus Action for Popup Source: https://github.com/mijick/popups/wiki/Popup-Declaration Optionally implement the 'onFocus' method to define a custom action that is triggered whenever the popup becomes the active one on the stack. This example prints a message to the console. ```swift struct BottomCustomPopup: BottomPopup { var body: some View { HStack(spacing: 0) { Text("Hello World") Spacer() Button(action: { Task { await dismissLastPopup() }}) { Text("Dismiss") } } .padding(.vertical, 20) .padding(.leading, 24) .padding(.trailing, 16) } func configurePopup(config: BottomPopupConfig) -> BottomPopupConfig { config .horizontalPadding(20) .bottomPadding(42) .cornerRadius(16) } func onDismiss() { print("Popup dismissed") } func onFocus() { print("Popup is now active") } } ``` -------------------------------- ### Presenting a Popup Source: https://github.com/mijick/popups/blob/main/_autodocs/DOCUMENTATION_SUMMARY.txt Demonstrates how to asynchronously present a popup using its present() method within a Task block. ```swift Task { await MyPopup().present() } ``` -------------------------------- ### Custom PopupSceneDelegate Implementation Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/popup-scene-delegate.md Example of overriding the sceneStoppedBeingFirstResponder method in a custom PopupSceneDelegate subclass to print a message when the scene loses focus. ```swift class CustomPopupSceneDelegate: PopupSceneDelegate { override func sceneStoppedBeingFirstResponder() { print("Scene lost focus") } } ``` -------------------------------- ### configurePopup(config:) Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/popup-protocol.md Configures the popup with custom settings. This method is called when the popup is created, allowing for customization before presentation. If not overridden, it inherits configuration from GlobalConfigContainer. ```APIDOC ## configurePopup(config:) ### Description Configures the popup with custom settings. Allows customization of specific settings for this popup instance before it is presented. If not overridden, the popup inherits configuration from `GlobalConfigContainer`. ### Method func configurePopup(config: Config) -> Config ### Parameters #### Path Parameters - **config** (Config) - Required - The configuration object to customize ### Response #### Success Response - **Config** - The modified configuration object ### Request Example ```swift struct MyPopup: CenterPopup { func configurePopup(config: CenterPopupConfig) -> CenterPopupConfig { config .cornerRadius(44) .backgroundColor(.blue) .tapOutsideToDismissPopup(true) } var body: some View { Text("Hello!") } } ``` ``` -------------------------------- ### Presenting Popups Source: https://github.com/mijick/popups/blob/main/_autodocs/INDEX.md Use `present()` to show a popup. You can optionally specify a custom stack ID. Configuration options like custom ID, environment objects, dismissal timers, and keyboard behavior can be chained before presenting. ```swift // Present popup await MyPopup().present() await MyPopup().present(popupStackID: .custom) // With configuration await MyPopup() .setCustomID("id") .setEnvironmentObject(viewModel) .dismissAfter(2.0) .dismissKeyboardOnDismissal(false) .present() ``` -------------------------------- ### Dismissing Last Popup from View Extension Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/dismissal-methods.md Example of using the `dismissLastPopup` view extension method within a popup's content to close itself. ```swift struct PopupContent: View { var body: some View { VStack { Text("Hello from popup") Button("Close") { Task { // Using view extension instead of PopupStack await self.dismissLastPopup() } } } } } ``` -------------------------------- ### Configure Shared Popups with Custom Builder Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/popup-stack-id.md Demonstrates how to apply a shared configuration to popups using a custom configuration builder function. This allows for consistent styling or behavior across different popup stacks. ```swift func sharedPopupConfig(_ config: GlobalConfigContainer) -> GlobalConfigContainer { config .vertical { $0.cornerRadius(16) } .center { $0.cornerRadius(16) } } @main struct App: App { var body: some Scene { WindowGroup { ContentView() .registerPopups(id: .shared, configBuilder: sharedPopupConfig) } } } ``` -------------------------------- ### Global and Per-Popup Configuration Source: https://github.com/mijick/popups/blob/main/_autodocs/INDEX.md Details on how to configure popup appearance globally using `registerPopups` and per-popup using a configuration function. ```APIDOC ## Popup Configuration ### Description Allows for customization of popup appearance and behavior. Configuration can be applied globally to all popups or specifically to individual popups. ### Method `registerPopups(config: (Config) -> Void)`, `configurePopup(config: Config) -> Config` ### Endpoint N/A (SDK Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```swift // Global configuration .registerPopups { config in config .vertical { $0.cornerRadius(20) } .center { $0.backgroundColor(.white) } } // Per-popup configuration func configurePopup(config: Config) -> Config { config.cornerRadius(24) } ``` ### Response #### Success Response None #### Response Example None ``` -------------------------------- ### Popup Presentation Source: https://github.com/mijick/popups/blob/main/_autodocs/INDEX.md Demonstrates how to present popups, including basic presentation, presentation with a custom stack ID, and presentation with various configurations. ```APIDOC ## Popup Presentation ### Description Allows for the presentation of popups to the user interface. Supports basic presentation, specifying a custom stack, and applying various configurations before presentation. ### Method `present()` ### Endpoint N/A (SDK Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```swift // Present popup await MyPopup().present() await MyPopup().present(popupStackID: .custom) // With configuration await MyPopup() .setCustomID("id") .setEnvironmentObject(viewModel) .dismissAfter(2.0) .dismissKeyboardOnDismissal(false) .present() ``` ### Response #### Success Response None (asynchronous operation) #### Response Example None ``` -------------------------------- ### Registering Popup Stack ID Source: https://github.com/mijick/popups/blob/main/_autodocs/quick-start.md Register a custom `popupStackID` before presenting a popup to avoid errors. This example shows the correct way to register a custom ID. ```swift // ❌ Will fail - stack not registered await MyPopup().present(popupStackID: .custom) // ✓ Fix - register first ContentView() .registerPopups(id: .custom) ``` -------------------------------- ### Listing Documentation Files Source: https://github.com/mijick/popups/blob/main/_autodocs/README.md This snippet displays a list of documentation files related to the popup library. It is for informational purposes and does not contain executable code. ```text /api-reference/ ├── popup-protocol.md - Core Popup protocol ├── popup-methods.md - Presentation methods ├── popup-stack.md - Stack management ├── popup-stack-id.md - Stack identification ├── view-registration.md - Framework setup ├── dismissal-methods.md - Dismissal operations └── popup-scene-delegate.md - iOS scene delegate types.md - Type and enum reference configuration.md - Configuration guide quick-start.md - Getting started examples README.md - This file ``` -------------------------------- ### LocalConfigCenter Configuration Methods Source: https://github.com/mijick/popups/blob/main/_autodocs/types.md Methods to configure the appearance and behavior of center popups. ```APIDOC ## LocalConfigCenter Configuration Methods ### Description Methods to programmatically set configuration values for center popups. ### Methods - `popupHorizontalPadding(_ value: CGFloat) -> Self`: Sets the horizontal padding for the popup. - `cornerRadius(_ value: CGFloat) -> Self`: Sets the corner radius for the popup. - `backgroundColor(_ color: Color) -> Self`: Sets the background color of the popup. - `overlayColor(_ color: Color) -> Self`: Sets the overlay color behind the popup. - `tapOutsideToDismissPopup(_ value: Bool) -> Self`: Enables or disables dismissing the popup by tapping outside of it. ``` -------------------------------- ### Implement OnDismiss Action for Popup Source: https://github.com/mijick/popups/wiki/Popup-Declaration Optionally implement the 'onDismiss' method to define a custom action that is executed when the popup is dismissed. This example prints a message to the console. ```swift struct BottomCustomPopup: BottomPopup { var body: some View { HStack(spacing: 0) { Text("Hello World") Spacer() Button(action: { Task { await dismissLastPopup() }}) { Text("Dismiss") } } .padding(.vertical, 20) .padding(.leading, 24) .padding(.trailing, 16) } func configurePopup(config: BottomPopupConfig) -> BottomPopupConfig { config .horizontalPadding(20) .bottomPadding(42) .cornerRadius(16) } func onDismiss() { print("Popup dismissed") } } ``` -------------------------------- ### Transparent Overlay Configuration Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/view-registration.md Configure popups to have a transparent overlay, useful when the popup content should not be obscured by a semi-transparent background. ```swift .registerPopups { config in config .center { $0.overlayColor(.clear) } .vertical { $0.overlayColor(.clear) } } ``` -------------------------------- ### onFocus() Lifecycle Callback Source: https://github.com/mijick/popups/blob/main/_autodocs/quick-start.md Implement the `onFocus()` method to execute code when a popup becomes the active, top-most element. Use this for refreshing data or starting animations. ```swift struct MyPopup: CenterPopup { func onFocus() { print("Popup is now on top") // Refresh data, start animation, etc. } var body: some View { Text("Active popup") } } ``` -------------------------------- ### PopupSceneDelegate makeSceneKey Method Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/popup-scene-delegate.md Makes the window the key window. ```swift open func makeSceneKey() ``` -------------------------------- ### LocalConfigVertical Configuration Methods Source: https://github.com/mijick/popups/blob/main/_autodocs/types.md Provides methods to customize various aspects of the popup's configuration. ```APIDOC ## LocalConfigVertical Configuration Methods ### Description Provides methods to customize various aspects of the popup's configuration. ### Methods - `popupTopPadding(_ value: CGFloat) -> Self`: Sets the top padding for the popup. - `popupBottomPadding(_ value: CGFloat) -> Self`: Sets the bottom padding for the popup. - `popupHorizontalPadding(_ value: CGFloat) -> Self`: Sets the horizontal padding for the popup. - `cornerRadius(_ value: CGFloat) -> Self`: Sets the corner radius for the popup. - `ignoreSafeArea(edges: Edge.Set) -> Self`: Configures the safe area insets. - `backgroundColor(_ color: Color) -> Self`: Sets the background color of the popup. - `overlayColor(_ color: Color) -> Self`: Sets the overlay color. - `heightMode(_ value: HeightMode) -> Self`: Sets the height mode of the popup. - `dragDetents(_ value: [DragDetent]) -> Self`: Defines the available drag detents for the popup. - `tapOutsideToDismissPopup(_ value: Bool) -> Self`: Enables or disables dismissing the popup by tapping outside. - `enableDragGesture(_ value: Bool) -> Self`: Enables or disables the drag gesture for the popup. - `dragGestureAreaSize(_ value: CGFloat) -> Self`: Sets the size of the area that triggers the drag gesture. ``` -------------------------------- ### Define Popup Body Source: https://github.com/mijick/popups/wiki/Popup-Declaration Implement the 'body' variable to define the visual content and layout of your custom popup. This example shows a simple HStack with text and a dismiss button. ```swift struct BottomCustomPopup: BottomPopup { var body: some View { HStack(spacing: 0) { Text("Hello World") Spacer() Button(action: { Task { await dismissLastPopup() }}) { Text("Dismiss") } } .padding(.vertical, 20) .padding(.leading, 24) .padding(.trailing, 16) } } ``` -------------------------------- ### Showing Popups from a ViewModel Source: https://github.com/mijick/popups/blob/main/_autodocs/README.md Illustrates how to trigger popup presentation from a ViewModel using an async method. The ViewModel must be observable and manage the presentation logic. ```swift class ViewModel: ObservableObject { @MainActor func showPopup() async { await MyPopup().present() } } ``` -------------------------------- ### Present a Simple Popup Source: https://github.com/mijick/popups/blob/main/_autodocs/README.md Define a popup conforming to CenterPopup and present it asynchronously within a Task. ```swift struct MyPopup: CenterPopup { var body: some View { Text("Hello") } } Task { await MyPopup().present() } ``` -------------------------------- ### LocalConfigVertical Configuration Methods Source: https://github.com/mijick/popups/blob/main/_autodocs/types.md Provides methods to configure various properties of the LocalConfigVertical class, such as padding, corner radius, colors, and drag gesture behavior. ```swift func popupTopPadding(_ value: CGFloat) -> Self func popupBottomPadding(_ value: CGFloat) -> Self func popupHorizontalPadding(_ value: CGFloat) -> Self func cornerRadius(_ value: CGFloat) -> Self func ignoreSafeArea(edges: Edge.Set) -> Self func backgroundColor(_ color: Color) -> Self func overlayColor(_ color: Color) -> Self func heightMode(_ value: HeightMode) -> Self func dragDetents(_ value: [DragDetent]) -> Self func tapOutsideToDismissPopup(_ value: Bool) -> Self func enableDragGesture(_ value: Bool) -> Self func dragGestureAreaSize(_ value: CGFloat) -> Self ``` -------------------------------- ### Comprehensive All Platforms Configuration Source: https://github.com/mijick/popups/blob/main/_autodocs/configuration.md Configure both vertical and center popups for all platforms, specifying drag gestures, tap-to-dismiss, corner radius, padding, background colors, and drag detents for vertical popups. ```swift @main struct MyApp: App { var body: some Scene { WindowGroup { ContentView() .registerPopups { config in config .vertical { vertical in vertical .enableDragGesture(true) .tapOutsideToDismissPopup(true) .cornerRadius(32) .popupBottomPadding(20) .dragDetents([ .fraction(0.33), .fraction(0.66), .large ]) .enableStacking(true) } .center { center in center .tapOutsideToDismissPopup(false) .backgroundColor(.white) .overlayColor(.black.opacity(0.6)) .cornerRadius(24) .popupHorizontalPadding(16) } } } } } ``` -------------------------------- ### Center Popup Configuration Methods Source: https://github.com/mijick/popups/blob/main/_autodocs/types.md Provides methods to configure various properties of a center popup, such as padding, corner radius, background color, overlay color, and tap-to-dismiss behavior. ```swift func popupHorizontalPadding(_ value: CGFloat) -> Self ``` ```swift func cornerRadius(_ value: CGFloat) -> Self ``` ```swift func backgroundColor(_ color: Color) -> Self ``` ```swift func overlayColor(_ color: Color) -> Self ``` ```swift func tapOutsideToDismissPopup(_ value: Bool) -> Self ``` -------------------------------- ### Multi-Window Popup Registration with IDs Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/view-registration.md Set up popups for applications with multiple windows by registering each window with a unique PopupStackID. This ensures popups are presented in the correct window context. ```swift @main struct MyApp: App { var body: some Scene { Window("Main", id: "main") { MainWindowContent() .registerPopups(id: .main) } Window("Secondary", id: "secondary") { SecondaryWindowContent() .registerPopups(id: .secondary) } } } extension PopupStackID { static let main: Self = .init(rawValue: "main") static let secondary: Self = .init(rawValue: "secondary") } struct MainWindowContent: View { var body: some View { Button("Show in Main") { Task { await MyPopup().present(popupStackID: .main) } } } } struct SecondaryWindowContent: View { var body: some View { Button("Show in Secondary") { Task { await MyPopup().present(popupStackID: .secondary) } } } } ``` -------------------------------- ### GlobalConfig Protocol Definition Source: https://github.com/mijick/popups/blob/main/_autodocs/types.md Defines default settings for all popups, including drag threshold and stacking behavior. Use this protocol to configure global popup behavior. ```swift @MainActor public protocol GlobalConfig: LocalConfig { var dragThreshold: CGFloat { get set } var isStackingEnabled: Bool { get set } } ``` -------------------------------- ### Minimal Popup Registration Source: https://github.com/mijick/popups/blob/main/_autodocs/configuration.md Use this snippet for the simplest popup registration, which applies all default settings. ```swift @main struct MyApp: App { var body: some Scene { WindowGroup { ContentView() .registerPopups() // Uses all defaults } } } ``` -------------------------------- ### Global Popup Configuration Source: https://github.com/mijick/popups/blob/main/_autodocs/README.md Configure default styles for different popup alignments using a closure passed to .registerPopups(). ```swift .registerPopups { config in config .vertical { $0.cornerRadius(20) } .center { $0.backgroundColor(.white) } } ``` -------------------------------- ### Global and Specific Popup Configuration Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/view-registration.md Register popups globally with default configurations and override them for specific popup types. The specific popup configuration takes precedence. ```swift // Global configuration (applies to all center popups) .registerPopups { config in config.center { $0.cornerRadius(16) } } // Specific popup override (takes precedence) struct MyPopup: CenterPopup { func configurePopup(config: CenterPopupConfig) -> CenterPopupConfig { config.cornerRadius(32) // Overrides global 16 } var body: some View { Text("Hello") } } ``` -------------------------------- ### Apply Minimal/Flat Design to Popups Source: https://github.com/mijick/popups/blob/main/_autodocs/configuration.md Configure popups for a minimal or flat design by setting corner radius to 0, using a white background, and a clear overlay. This creates a clean and unobtrusive appearance. ```swift .registerPopups { config in config .vertical { $0 .cornerRadius(0) .backgroundColor(.white) .overlayColor(.clear) } .center { $0 .cornerRadius(0) .backgroundColor(.white) .overlayColor(.clear) } } ``` -------------------------------- ### Using Shared PopupStackID for Presenting and Dismissing Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/popup-stack-id.md Demonstrates equivalent calls for presenting a popup and dismissing the last popup using the default '.shared' stack ID. ```swift // These are equivalent when using the default stack: await MyPopup().present() await MyPopup().present(popupStackID: .shared) // Dismiss from default stack: await PopupStack.dismissLastPopup() await PopupStack.dismissLastPopup(popupStackID: .shared) ``` -------------------------------- ### Fullscreen Popup Configuration Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/view-registration.md Set popups to occupy the entire screen by configuring their height mode to fullscreen. ```swift .registerPopups { config in config.vertical { $0.heightMode(.fullscreen) } } ``` -------------------------------- ### Create a Configurable Center Popup (Alert/Modal) Source: https://github.com/mijick/popups/blob/main/_autodocs/quick-start.md Define a `CenterPopup` with custom configuration options like corner radius, background color, and dismiss behavior. This is useful for alerts or modals. ```swift struct AlertPopup: CenterPopup { let title: String let message: String func configurePopup(config: CenterPopupConfig) -> CenterPopupConfig { config .cornerRadius(20) .backgroundColor(.white) .tapOutsideToDismissPopup(true) } var body: some View { VStack(spacing: 16) { Text(title).font(.headline) Text(message) Button("Close") { Task { await PopupStack.dismissLastPopup() } } } .padding() } } ``` -------------------------------- ### Update App Entry Point Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/popup-scene-delegate.md Ensure your application's main struct adopts UIApplicationDelegateAdaptor to use the configured AppDelegate. ```swift import SwiftUI @main struct MyApp: App { @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate var body: some Scene { WindowGroup { ContentView() } } } ``` -------------------------------- ### Compare PopupStackIDs Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/popup-stack-id.md Demonstrates how to compare PopupStackIDs for equality using their Equatable conformance. This is useful for verifying if two IDs refer to the same popup stack. ```swift let id1 = PopupStackID(rawValue: "stack1") let id2 = PopupStackID(rawValue: "stack1") let id3 = PopupStackID(rawValue: "stack2") id1 == id2 // true id1 == id3 // false ``` -------------------------------- ### present(popupStackID:) Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/popup-methods.md Presents the popup in the specified popup stack asynchronously. This method must be called from the main thread. The popup is added to the given stack and displayed based on its configuration and the stack's current state. The `popupStackID` must be registered beforehand. ```APIDOC ## present(popupStackID:) ### Description Presents the popup in the specified popup stack asynchronously. This method must be called from the main thread. The popup is added to the given stack and displayed based on its configuration and the stack's current state. The `popupStackID` must be registered beforehand. ### Method `async` ### Parameters #### Path Parameters - **popupStackID** (`PopupStackID`) - Optional - The identifier of the registered popup stack where this popup will be displayed. Defaults to `.shared`. ### Throws Logs a fault-level error if the specified `popupStackID` has not been registered with `registerPopups(id:configBuilder:)`. ### Example ```swift struct MyView: View { var body: some View { Button("Show Popup") { Task { await MyPopup().present() } } } } struct MyPopup: CenterPopup { var body: some View { Text("Hello!") } } ``` **With Custom Stack ID:** ```swift Task { await MyPopup().present(popupStackID: .custom1) } extension PopupStackID { static let custom1: Self = .init(rawValue: "custom1") } ``` ``` -------------------------------- ### Manage Multiple Popups of the Same Type with Custom IDs Source: https://github.com/mijick/popups/blob/main/_autodocs/README.md Demonstrates how to present multiple popups of the same type, assign them custom identifiers, and then dismiss specific ones or all of that type using static methods on `PopupStack`. ```swift // Present with custom IDs await ErrorPopup(message: "Error 1").setCustomID("error-1").present() await ErrorPopup(message: "Error 2").setCustomID("error-2").present() // Dismiss specific one await PopupStack.dismissPopup("error-1") // Or dismiss all of that type await PopupStack.dismissPopup(ErrorPopup.self) ``` -------------------------------- ### GlobalConfig Protocol Source: https://github.com/mijick/popups/blob/main/_autodocs/types.md Configuration protocol for default settings applied to all popups. It allows customization of drag thresholds and stacking behavior. ```APIDOC ## GlobalConfig Protocol ### Description Configuration protocol for default settings applied to all popups. It allows customization of drag thresholds and stacking behavior. ### Properties - **dragThreshold** (CGFloat) - Progress value above which popup dismisses or moves to next detent (0–1) - **isStackingEnabled** (Bool) - Whether multiple popups are visible stacked behind the active one ``` -------------------------------- ### Integrating PopupSceneDelegate with Native SwiftUI Sheets Source: https://github.com/mijick/popups/blob/main/_autodocs/api-reference/popup-scene-delegate.md This snippet demonstrates how to present a MijickPopup while also allowing a native SwiftUI sheet to be displayed. Ensure your `MyPopup` class is correctly defined elsewhere. ```swift struct ContentView: View { @State var showNativeSheet = false var body: some View { VStack { Button("Show MijickPopup") { Task { await MyPopup().present() } } Button("Show Native Sheet") { showNativeSheet = true } } .sheet(isPresented: $showNativeSheet) { Text("Native Sheet") } } } ``` -------------------------------- ### Per-Popup Configuration Source: https://github.com/mijick/popups/blob/main/_autodocs/quick-start.md Customize individual popups by conforming to a popup protocol (e.g., `BottomPopup`) and implementing the `configurePopup` method. This allows overriding global settings for specific popups, such as corner radius, background color, and height mode. ```swift struct MyPopup: BottomPopup { func configurePopup(config: BottomPopupConfig) -> BottomPopupConfig { config .cornerRadius(24) .backgroundColor(.blue) .heightMode(.auto) } var body: some View { Text("Custom") } } ``` -------------------------------- ### Per-Popup Configuration Source: https://github.com/mijick/popups/blob/main/_autodocs/README.md Define a function to return a custom configuration for a specific popup, overriding global settings. ```swift func configurePopup(config: Config) -> Config { config.cornerRadius(24) } ``` -------------------------------- ### Global Popup Configuration Source: https://github.com/mijick/popups/blob/main/_autodocs/INDEX.md Configure default popup appearance and behavior globally using `registerPopups`. This allows for consistent styling across all popups, such as setting corner radius or background color. ```swift // Global .registerPopups { config in config .vertical { $0.cornerRadius(20) } .center { $0.backgroundColor(.white) } } ``` -------------------------------- ### Integrating Popups with NavigationStack Source: https://github.com/mijick/popups/blob/main/_autodocs/README.md Demonstrates how to use popups within a NavigationStack. The `.registerPopups()` modifier should be applied to the navigation stack. ```swift NavigationStack { ContentView() .navigationDestination(for: Item.self) { item in DetailView(item) } } .registerPopups() ``` -------------------------------- ### Presenting Popups with Native Sheets Source: https://github.com/mijick/popups/blob/main/_autodocs/README.md Shows how to present a custom popup alongside a native SwiftUI sheet. Ensure your popup is defined and accessible. ```swift struct MyView: View { @State var showSheet = false var body: some View { VStack { Button("Show Popup") { Task { await MyPopup().present() } } Button("Show Sheet") { showSheet = true } } .sheet(isPresented: $showSheet) { Text("Native Sheet") } } } ```