Swiftpack.co - Package - impresyjna/ImpressiveNotifications
Gallery Banner

Version Carthage Compatible License Platform Swift

Description

ImpressiveNotifications are custom in-app notifications with 3 types of layouts. The notifications will animate in and out. They will hide when they are clicked on or with an automatic dismissal. It is also available to add custom behavior when notification is tapped.

Installation

ImpressiveNotifications is available through Carthage. To install just write into your Cartfile:

github "impresyjna/ImpressiveNotifications"

ImpressiveNotifications is also available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'ImpressiveNotifications'

ImpressiveNotifications is also available through Swift Package Manager. The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Usage

Call INNotifications.show with a window where it should be shown, type, data structure and customStyle if you want. Only type is necessary.

Built-in notification types are : .success .warning .danger .custom(UIView)

Example:

INNotifications.show(in: UIApplication.shared.keyWindow, type: .danger, data: INNotificationData(title: "Error", description: "Error notification"))

Configuration

ImpressiveNotifications gives user possibility to customize view.

Custom style

INNotificationStyle is the structure created to customize the appearance of notification.

public struct INNotificationStyle {
    let cornerRadius: CGFloat?
    let backgroundColor: UIColor?
    let titleColor: UIColor?
    let descriptionColor: UIColor?
    let imageSize: CGSize?
    let verticalMargin: CGFloat // Vertical margin for whole notification
    let horizontalMargin: CGFloat // Horizontal margin for whole notification (trailing and leading) 
}

Example:

INNotifications.show(in: UIApplication.shared.keyWindow, type: .danger, data: INNotificationData(title: "Error", description: "Error notification"), customStyle: INNotificationStyle(cornerRadius: 10.0, backgroundColor: .black, titleColor: .red, descriptionColor: .yellow, imageSize: CGSize(width: 100.0, height: 100.0)))

Custom data, time and completionHandler

INNotificationData is the structure created to customize data on the notification, time and add completionHandler on tap. From version 0.8.0 is added parent delegate with methods for finish (when notification hides because of delay) and tap on the view. It is alternative to completionHandler on tap.

public struct INNotificationData {
    let title: String
    let description: String?
    let image: UIImage?
    let delay: TimeInterval?
    let parentDelegate: INNotificationDelegate?
    let completionHandler: (() -> Void)?
    let hideOnTap: Bool
}

Example:

INNotifications.show(in: UIApplication.shared.keyWindow, type: .danger, data: INNotificationData(title: "Danger", description: "Danger notification", image: UIImage(named: "danger"), delay: 20.0, completionHandler: {
            print("Hello")
    }
))

If you want to make constant notification(without hiding timer), in INNotificationData delay should be nil. If you want to block hiding on tap just set hideOnTap in this struct as false. To hide the notification is created INNotifications.hide() method.

INNotificationDelegate

INNotificationDelegate is used to notify about finish or tap on notification. It has two functions:

func impressiveNotificationTapped()
func impressiveNotificationFinished()

Custom view

It is also possible to add custom view created for example in storyboard.

Example:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "CustomViewController")

INNotifications.show(in: UIApplication.shared.keyWindow, type: .custom(vc.view))

Position

INNotificationPosition is enum for setup position of notification (top or bottom).

Example:

INNotifications.show(in: UIApplication.shared.keyWindow, type: .danger, data: INNotificationData(title: "Error", description: "Error notification"), position: .bottom)

Github

link
Stars: 26

Dependencies

Used By

Total: 0

Releases

- 2019-11-26 09:05:41

- 2019-09-19 07:41:18

- 2019-06-05 10:12:32

- 2019-06-04 12:41:40

- 2019-05-31 11:05:22

- 2019-05-31 09:41:34

- 2019-05-31 08:26:03

- 2019-05-30 07:32:55

- 2019-04-14 18:44:04

- 2019-04-10 12:42:15

- 2019-03-19 10:11:46

- 2019-03-18 12:18:22

Added ability to show notification on top or on the bottom - 2019-02-27 12:47:50