iOSAlertLibrary is a SwiftUI-based notification library that works seamlessly on any screen.
Toasts | Dynamic island | Alerts |
---|---|---|
![]() |
![]() |
![]() |
- ✅ Predefined notifications with various designs and configurations.
- ✅ Toast notifications with adjustable size on tap.
- ✅ Notifications for Dynamic Island.
- ✅ Built-in animations with customizable parameters.
- ✅ Support for custom notification UI.
- ✅ Gesture support (swipes in four directions, taps).
- ✅ Notifications displayed above any screen.
- ✅ Full dark mode adaptation.
- ✅ Screen rotation support.
- ✅ Available via Swift Package Manager (SPM).
- ✅ UI tests to ensure functionality.
The library provides an intuitive interface for creating and displaying notifications. You can use predefined templates or integrate custom UI.
// Create an instance of the library
let iosAlertLibrary = iOSAlertLibrary()
// Generate a unique ID for the notification
let id = UUID().uuidString
// Configure the notification
let alertConfig = AlertConfig(
icon: "trash.fill",
lightModeIconColor: .blue,
darkModeIconColor: .blue.opacity(0.8),
title: "Storage Full!",
lightModeTitleColor: .black,
darkModeTitleColor: .white,
message: """
Your cloud storage is full. You can no longer save data. \
Delete unnecessary files or upgrade your plan.
""",
lightModeMessageColor: .gray,
darkModeMessageColor: .gray,
lightModeBackgroundColor: .white,
darkModeBackgroundColor: Color(white: 0.15),
dismissAction: { [weak self] in self?.iosAlertLibrary.dismissAlert(id: id) },
cancelButtonConfig: nil,
continueButtonConfig: AlertButtonConfig(
title: "Upgrade Plan",
action: { print("Plan upgraded") },
lightModeTitleColor: .white,
darkModeTitleColor: .white,
lightModeBackgroundColor: .blue,
darkModeBackgroundColor: .blue
)
)
// Create the alert view
let alert = AlertView(config: alertConfig)
// Configure the alert container
let containerConfig = ContainerConfig(
id: id,
duration: 3,
position: .top,
gestures: [.swipe(direction: [.up], threshold: 20)],
animationType: .slide,
animationConfig: AnimationConfig(
offset: (x: (start: -50, end: 0), y: (start: 0, end: 0)),
opacity: (start: 0, end: 1),
scaleEffect: (from: 1, anchor: .center)
)
)
// Create the alert container
let container = BasicContainerView(content: alert, containerConfig: containerConfig)
// Display the notification
iosAlertLibrary.showAlert(container: container, useOverlayWindow: false)
// Force dismiss the notification
iosAlertLibrary.dismissAlert(id: id)
The library's architecture is modular, allowing you to use only the required functionality.
- Alerts UI presets - A collection of predefined notification templates.
- BasicContainerView - An intermediate wrapper for UI elements (View), enabling gesture and animation configuration, and implementing the ContainerViewProtocol.
- AlertPresentationManager - Manages the display of containers (Views implementing ContainerViewProtocol) and their lifecycle.
Platform |
---|
iOS 16.0+ |