Skip to content

🌿 iOS Library for Convenient Toast Message UI & Animation!

License

Notifications You must be signed in to change notification settings

ValseLee/CLToaster

Repository files navigation

🌿 CLToaster

Deploy Version GitHub Repo stars GitHub Release

iOS Library for Presenting Toast Message in UIKit & SwiftUI
Easy to Use, Easy to Customize || Convenient and Consistent

CLToastBanner

🧩 Examples!

Quick Toast Detailed Toast Animation Customized Toast Top Toast
1.mp4
2.mp4
3.mp4
4.mp4

Easy-to-use

  1. You can simply initialize CLToast and present.
  2. You can use CLToastStyle struct to manage toast message’s Title, Description, Image, and Timeline.
  3. Basic animation/transition(offset & opacity) is provided by the framework.

Easy-to-customize

  1. You can customize animation/transition with your own taste.
  2. In UIKit, you will conform the protocol CLToastUIKitAnimation.
  3. Otherwise, In SwiftUI, you will conform the protocol CLToastSwiftUITransition.

👀 Let's see how it works!


Basics

  • With CLToast, You can present a toast message using several methods.
  • Whether you use UIKit or SwiftUI, CLToast can be used consistently.
  • Follow the examples below.

Quick Toast with title and height.

// UIKit
CLToast(title: "Title", height: 50)
  .present(in: view)

// SwiftUI
var body: some View {
  YourView { /* code */ }
    .presentToast(
      isPresented: $isPresented,
      title: "Title",
      height: 50
    )
}

Detailed Toast message with style.

  • CLToastStyle can be used in UIKit and SwiftUI equally.
  • You can make common style and use it consistently in UIKit and SwiftUI.
// Common style
var style = CLToastStyle(title: "Title")
style.description = "Description"
style.timeline = Date().formatted()
style.image = UIImage(named: "MyImage")

// UIKit
CLToast(with: style)
  .present(in: view)

// SwiftUI
var body: some View {
  YourView { /* code */ }
    .presentToast(
      isPresented: $isPresented,
      with: style
    )
}

Presenting toast message from top.

  • You can present your toast message from top, center and bottom.
  • CLToast will present your toast from bottom by default.
    • in Quick Present, you can’t present it from other direction but bottom.
  • Default animation will be automatically adjusted by its presentation section.
var style = CLToastStyle(title: "Title")
style.description = "Description"
style.timeline = Date().formatted()
style.image = UIImage(named: "MyImage")

// UIKit
CLToast(with: style, section: .top)
  .present(in: view)

// SwiftUI
var body: some View {
  YourView { /* code */ }
    .presentToast(
      isPresented: $isPresented,
      with: style,
      section: .top
    )
}

Customize your toast message with your animation.

  • You can customize toast message’s animation/transition.
  • You have to make an implementation of CLToastUIKitAnimation or CLToastSwiftUITransition.
  • Each of protocol will provide you a blueprint.
  • WORK IN PROCESS!
// 1. First, you need ``CLToastAnimations`` which has animationSpeed and displayTime, etc.
// This animation model is also can be used commonly in UIKit, and SwiftUI.
var animation = CLToastAnimations()
animation.animatonSpeed = 0.5
animation.displayTime = 1.5

// 2. Then you make an implementation of ``CLToastUIKitAnimation`` or ``CLToastSwiftUITransition``.
struct MyCLToastAnimation: CLToastUIKitAnimation {
  let toastAnimations: CLToastAnimations

  // 3. Here, You make an animation for when the toast message is appearing.
  func makeAppearingAnimation(toastView: UIView, for style: CLToastStyle) {
    toastView.layer.opacity = toastAnimations.opacity
    toastView.frame.origin.y += toastAnimation.offsetY
    toastView.frame.origin.x += 40
  }

  // 4. Make an animation for when the toast message is disappearing.
  func makeDisappearingAnimation(toastView: UIView, for style: CLToastStyle) {
    toastView.layer.opacity = 0
    toastView.frame.origin.y -= toastAnimation.offsetY
  }

  // 5. Make an animator which manages above animations.
  func makeAnimation() -> UIViewPropertyAnimator {
    return UIViewPropertyAnimator(
      duration: toastAnimations.animationSpeed,
      curve: .easeInOut
    )
  }
}

// 6. With above CLToastAnimations, initialize your animation implementation.
let animationImplementation = MyCLToastAnimation(toastAnimations: animation)

// 7. ✨ And it's done!
CLToast(with: style, animation: animationImplementation)
  .present(in: view)

Cocoapods

pod 'CLToaster'

Swift Package Manager

Package URL: https://github.com/ValseLee/CLToaster/
branch: `main`

Carthage

WORK-IN-PROCESS


Update Roadmap

CLToaster is in beta, so it would be updating continuously.
And it might take some time to update below items.

View Customize Animation Customize Gesture Customize Apply Queue 🚏 More
UIKit
SwiftUI

It is Opened to everyone, btw.

  • Your idea and issue really matter.
  • Tell me with issue or fork this repository and make PR to contribute!

About

🌿 iOS Library for Convenient Toast Message UI & Animation!

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published