Create beautiful and fully customisable popups in no time. Keep your code clean
PopupView is a free and open-source library dedicated for SwiftUI that makes the process of presenting popups easier and much cleaner.
showAndStack()
or showAndReplace()
method.dismiss()
. Simple as never.Platforms | Minimum Swift Version |
---|---|
iOS 14+ | 5.0 |
iPadOS 14+ | 5.0 |
macOS 12+ | 5.0 |
tvOS 15+ | 5.0 |
Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the Swift compiler.
Once you have your Swift package set up, adding PopupView as a dependency is as easy as adding it to the dependencies
value of your Package.swift
.
dependencies: [
.package(url: "https://github.com/Mijick/PopupView.git", branch(“main”))
]
Cocoapods is a dependency manager for Swift and Objective-C Cocoa projects that helps to scale them elegantly.
Installation steps:
pod init
Podfile
pod 'MijickPopupView'
.xcworkspace
file pod install
.xcworkspace
Inside your @main
structure call the implementPopupView
method. It takes the optional argument - config, that can be used to configure some modifiers for all popups in the application.
var body: some Scene {
WindowGroup(content: ContentView().implementPopupView)
}
The library provides an ability to present your custom view in three predefinied places - Top, Centre and Bottom.
In order to present it, it is necessary to confirm to one of the protocols during your view declaration:
TopPopup
- presents popup view from the topCentrePopup
- presents popup view from the centerBottomPopup
- presents popup view from the bottomSo that an example view you want to present will have the following declaration:
struct BottomCustomPopup: BottomPopup {
...
}
createContent()
methodThe function above is used instead of the body property, and declares the design of the popup view.
struct BottomCustomPopup: BottomPopup {
func createContent() -> some View {
HStack(spacing: 0) {
Text("Witaj okrutny świecie")
Spacer()
Button(action: dismiss) { Text("Dismiss") }
}
.padding(.vertical, 20)
.padding(.leading, 24)
.padding(.trailing, 16)
}
...
}
configurePopup(popup: Config) -> Config
methodDeclaring this step is optional - if you wish, you can skip this step and leave the UI configuration to us.
Each protocol has its own set of methods that can be used to create a unique appearance for every popup.
struct BottomCustomPopup: BottomPopup {
func createContent() -> some View {
HStack(spacing: 0) {
Text("Witaj okrutny świecie")
Spacer()
Button(action: dismiss) { Text("Dismiss") }
}
.padding(.vertical, 20)
.padding(.leading, 24)
.padding(.trailing, 16)
}
func configurePopup(popup: BottomPopupConfig) -> BottomPopupConfig {
popup
.horizontalPadding(20)
.bottomPadding(42)
.cornerRadius(16)
}
...
}
Just call BottomCustomPopup().showAndStack()
from the selected place. Popup can be closed automatically by adding the dismissAfter modifier.
struct SettingsViewModel {
...
func saveSettings() {
...
BottomCustomPopup()
.showAndStack()
.dismissAfter(5)
...
}
...
}
There are two methods to do so:
dismiss
, dismiss(_ popup: Popup.Type)
, dismissAll(upTo: Popup.Type)
, dismissAll
inside the popup you createdstruct BottomCustomPopup: BottomPopup {
...
func createButton() -> some View {
Button(action: dismiss) { Text("Tap to close") }
}
...
}
PopupManager.dismiss()
PopupManager.dismiss(_ popup: Popup.Type)
where popup is the popup you want to closePopupManager.dismissAll(upTo popup: Popup.Type)
where popup is the popup up to which you want to close the popups on the stackPopupManager.dismissAll()
See for yourself how does it work by cloning project we created
PopupView is released under the MIT license. See LICENSE for details.
Navigattie - Easier and cleaner way of navigating through your app
GridView - Lay out your data with no effort
Timer - Modern API for Timer
link |
Stars: 483 |
Last commit: 1 week ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics