space-code/snacker
## Description
Description
Snacker is a modern, lightweight Swift framework for displaying customizable snackbars and toast notifications in iOS applications. Designed with simplicity in mind, it allows developers to present any custom view as a non-intrusive notification with flexible positioning and smooth animations.
Features
β¨ Custom Views β Display any UIView as a snackbar π Flexible Positioning β Support for top and bottom screen alignments π¬ Smooth Animations β Fully configurable transition durations π― Simple API β Single-line execution via a shared service π± Modern Swift β Built for Swift 6.0 and iOS 17.0+ β‘ Lightweight β Minimal overhead with zero external dependencies π§ͺ Well Tested β Reliable performance for production environments
Table of Contents
Requirements
| Platform | Minimum Version | | --- | --- | | iOS | 17.0+ | | Xcode | 16.0+ | | Swift | 6.0+ |
Installation
Swift Package Manager
Add the following dependency to your Package.swift:
dependencies: [
.package(url: "https://github.com/space-code/snacker.git", from: "1.0.1")
]
Or add it through Xcode:
- File > Add Package Dependencies
- Enter package URL:
https://github.com/space-code/snacker.git - Select version requirements
Quick Start
import Snacker
let myView = MyCustomView() // Any UIView subclass
Snacker.shared.action(
.snack(
view: myView,
data: SnackbarData(
snackbarAlignment: .top(spacing: 20),
animationDuration: 0.25
)
),
container: window
)
Usage
Custom View Implementation
You can display any view as a snackbar. Here is a practical example of creating and presenting a simple information toast:
import UIKit
import Snacker
// 1. Define your custom notification view
final class InfoToastView: UIView {
private let messageLabel = UILabel()
init(text: String) {
super.init(frame: .zero)
backgroundColor = .secondarySystemBackground
layer.cornerRadius = 10
messageLabel.text = text
messageLabel.textAlignment = .center
messageLabel.translatesAutoresizingMaskIntoConstraints = false
addSubview(messageLabel)
NSLayoutConstraint.activate([
messageLabel.topAnchor.constraint(equalTo: topAnchor, constant: 12),
messageLabel.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -12),
messageLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16),
messageLabel.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -16)
])
}
required init?(coder: NSCoder) { fatalError() }
}
// 2. Present the snackbar
func notifyUser() {
let toast = InfoToastView(text: "New message received!")
let config = SnackbarData(
snackbarAlignment: .bottom(spacing: 50),
insets: UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20),
animationDuration: 0.3
)
Snacker.shared.action(
.snack(view: toast, data: config),
container: self.view.window
)
}
Communication
- π Found a bug? Open an issue
- π‘ Have a feature request? Open an issue
- β Questions? Start a discussion
- π Security issue? Email nv3212@gmail.com
Contributing
We love contributions! Please feel free to help out with this project. If you see something that could be made better or want a new feature, open up an issue or send a Pull Request.
Development Setup
Bootstrap the development environment:
mise installLicense
Snacker is released under the MIT license. See LICENSE for details.
<div align="center">
Made with β€οΈ by space-code
</div>
Package Metadata
Repository: space-code/snacker
Default branch: main
README: README.md