An easy-to-use UI component to display brief, transient messages to the user.
This framework allows you to add transient in-app messaging to your application. Multiple messages will stack using fluid animations. Messages can be fully themed and set to either expire after a specified time interval or to remain on-screen until dismissed.
Y—Snackbar is licensed under the Apache 2.0 license.
Documentation is automatically generated from source code comments and rendered as a static website hosted via GitHub Pages at: https://yml-org.github.io/ysnackbar-ios/
A Snack
is a model that represents a floating ephemeral alert or message to be presented to the user. It consists of the following:
alignment
: Alignment for the snack view. Default is SnackbarManager.defaultAlignment
.title
: Title for the snack view. This is an optional string and the default is nil.message
: Message to be displayed by SnackView
. This is of type String
.reuseIdentifier
: A string for identifying a snack. This is of type String?
and the default is nil.icon
: A small image to be displayed as part of the snack view. This is of type UIImage?
and the default is nil.duration
: The total duration for which the snack will be displayed. The default is 4 seconds.appearance
: Sets the appearance of the SnackView
. The default is .default
.Two snacks are said to be equal if either the reuseIdentifier
of both snacks are equal or the title
and message
of both snacks are equal. This is made possible by the snack’s conformance to both Equatable
and Hashable
.
💡 If the snack duration
is .nan
or .zero
then the snack lives forever (until you swipe to dismiss it)
A SnackView
is a view that will be presented to the user through the SnackbarManager
. The content of the view is populated using a Snack
model object. It has one initializer:
init(snack: Snack)
SnackView
using the snack
data model.Clients can modify or set the appearance of the SnackView
while creating a Snack
by setting the appearance
. This will allow the client to modify the following properties:
title
:
textColor
and typography
for the title label.(.label, .systemLabel.bold)
.message
:
textColor
and typography
for the message label.(.label, .systemLabel)
.backgroundColor
:
systemBackground
.borderColor
:
.label
.borderWidth
:
0
.elevation
:
Appearance.elevation
.layout
:
Layout()
.How to get SnackView
from a Snack
?
func getSnackAssociatedView() -> SnackUpdatable
Snack
model object.SnackView
uses this to update an existing view with new information.All snacks are managed by the SnackbarManager
.
defaultAlignment
.top
class func add(snack: Snack)
Creates a snack view using the snack passed as an argument to display a snack.
Depending on the alignment, duplicate snacks will be updated and pushed to the bottom or top.
class func remove(snack: Snack)
SnackContainerView
will be dismissed after the last snack is removed.class func remove(snack: Snack)
operation.duration
Clients can control or modify the animation duration, spacing, etc of the SnackbarManager
by setting the appearance
property which is of type SnackbarManager.Appearance
. This will allow the client to modify the following properties:
addAnimationDuration
:
removeAnimationDuration
:
snackSpacing
:
contentInset
:
maxSnackWidth
:
Every snack added has the following default features:
Importing the framework
import YSnackbar
Create a snack
func makeSnack() -> Snack {
Snack(
alignment: .bottom,
title: "Network Reachable",
message: "You are currently online.",
reuseIdentifier: "yml.co",
icon: UIImage(named: "wifi"),
duration: 8.0
)
}
Add a snack
// Creates a snack using `SnackbarManager.defaultAlignment = .top`
let snack = Snack(message: "No network")
// Adds to the top of the screen
SnackbarManager.add(snack: snack)
// Creates a snack with bottom alignment
let snack = Snack(alignment: .bottom, message: "Copied to clipboard")
// Adds to the bottom of the screen
SnackbarManager.add(snack: snack)
// Set `SnackbarManager.defaultAlignment` to bottom
SnackbarManager.defaultAlignment = .bottom
// Creates a snack using defaultAlignment.
let snack = Snack(message: "Copied to clipboard")
// Adds to the bottom of the screen
SnackbarManager.add(snack: snack)
Remove a snack
let snack = Snack()
SnackbarManager.remove(snack)
Create a custom Snack
final class ImageSnack: Snack {
convenience init(named: String) {
self.init(message: named, reuseIdentifier: "co.yml.page")
}
override func getSnackAssociatedView() -> SnackUpdatable {
SnackImageView(snack: self)
}
}
final class SnackImageView: UIImageView {
private(set) var snack: Snack
required init(snack: Snack) {
self.snack = snack
super.init(image: UIImage(named: snack.message))
setUp()
}
required init?(coder: NSCoder) { nil }
private func setUp() {
self.contentMode = .scaleAspectFit
}
}
extension SnackImageView: SnackUpdatable {
func update(_ snack: Snack) {
self.image = UIImage(named: snack.message)
self.snack = snack
}
}
Y—Snackbar depends upon our Y—CoreUI and Y—MatterType frameworks (both also open source and Apache 2.0 licensed).
You can add Y—Snackbar to an Xcode project by adding it as a package dependency.
brew install swiftlint
sudo gem install jazzy
Clone the repo and open Package.swift
in Xcode.
We utilize semantic versioning.
{major}.{minor}.{patch}
e.g.
1.0.5
We utilize a simplified branching strategy for our frameworks.
main
main
main
as they are completed and approved.main
gets tagged with an updated version # for each releasefeature/{ticket-number}-{short-description}
bugfix/{ticket-number}-{short-description}
e.g.
feature/CM-44-button
bugfix/CM-236-textview-color
Prior to submitting a pull request you should:
swiftlint
from the command line and confirm that there are no violations.jazzy
from the command line and confirm that you have 100% documentation coverage.git rebase -i HEAD~{commit-count}
to squash your last {commit-count} commits together into functional chunks.main
) has been updated since you created your branch, use git rebase main
to rebase your branch.
When submitting a pull request:
When merging a pull request:
1.0.5
)You can generate your own local set of documentation directly from the source code using the following command from Terminal:
jazzy
This generates a set of documentation under /docs
. The default configuration is set in the default config file .jazzy.yaml
file.
To view additional documentation options type:
jazzy --help
A GitHub Action automatically runs each time a commit is pushed to main
that runs Jazzy to generate the documentation for our GitHub page at: https://yml-org.github.io/ysnackbar-ios/
link |
Stars: 2 |
Last commit: 21 hours ago |
Initial Release
Full Changelog: https://github.com/yml-org/ysnackbar-ios/commits/1.0.0
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics