Skip to content
Tomasz K. edited this page Nov 17, 2024 · 50 revisions

Człowiek wyruszył na spotkanie innych światów, innych cywilizacji, nie poznawszy do końca własnych zakamarków, ślepych dróg, studni, zabarykadowanych, ciemnych drzwi.

Setup

This page presents various options for incorporating MijickPopups into your application. We begin by outlining the limitations of each method, helping you select the approach that best suits your requirements. While the code examples are based on iOS, they should also be compatible with other platforms such as macOS or tvOS.

Option 1: RegisterPopups

Note

This method DOES NOT work with native SwiftUI elements like sheets, alerts or popovers; popups will be "covered" by them.

Using registerPopups method

@main struct App_Main: App {
   var body: some Scene { WindowGroup {
       ContentView()
           .registerPopups(id: .shared) { config in config
               .vertical { $0
                   .enableDragGesture(true)
                   .tapOutsideToDismissPopup(true)
                   .cornerRadius(32)
               }
               .center { $0
                   .tapOutsideToDismissPopup(false)
                   .backgroundColor(.white)
               }
           }
   }}
}

Description

Inside the @main structure of your app, call the registerPopups() method. It takes two optional arguments:

  • id - It is possible to register a separate popup stack for each window. This is useful for applications that work with multiple windows.
  • configBuilder - Default configuration for all popups.

Option 2: SceneDelegate

Note

This method works ONLY with iOS

Steps

  1. Declare your CustomPopupSceneDelegate class inheriting from PopupSceneDelegate.
class CustomPopupSceneDelegate: PopupSceneDelegate {}
  1. Optional - Override CustomPopupSceneDelegate initializer and add your own popup configuration.
class CustomPopupSceneDelegate: PopupSceneDelegate {
   override init() { super.init()
       configBuilder = { $0
           .vertical { $0
               .enableDragGesture(true)
               .tapOutsideToDismissPopup(true)
               .cornerRadius(32)
           }
           .center { $0
               .tapOutsideToDismissPopup(false)
               .backgroundColor(.white)
           }
       }
   }
}
  1. Declare AppDelegate class conforming to NSObject and UIApplicationDelegate.
class AppDelegate: NSObject, UIApplicationDelegate {}
  1. Within AppDelegate declare func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) method.
class AppDelegate: NSObject, UIApplicationDelegate {
   func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {}
}
  1. Add CustomPopupSceneDelegate as delegateClass to the method from step 4.
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
   }
}
  1. Inside the @main structure of your app, declare new variable: UIApplicationDelegateAdaptor(AppDelegate.self).
@main struct App_Main: App {
   @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

   var body: some Scene { WindowGroup(content: ContentView.init) }
}
  1. All set!
@main struct App_Main: App {
   @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

   var body: some Scene { WindowGroup(content: ContentView.init) }
}

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
   }
}

class CustomPopupSceneDelegate: PopupSceneDelegate {
   override init() { super.init()
       configBuilder = { $0
           .vertical { $0
               .enableDragGesture(true)
               .tapOutsideToDismissPopup(true)
               .cornerRadius(32)
           }
           .center { $0
               .tapOutsideToDismissPopup(false)
               .backgroundColor(.white)
           }
       }
   }
}