Giter Site home page Giter Site logo

namanastapartners / spalert Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sparrowcode/alertkit

0.0 0.0 0.0 10.77 MB

Native alert from Apple Music & Feedback. Contains Done, Heart & Message and other presets. Support SwiftUI.

Home Page: https://opensource.ivanvorobei.io

License: MIT License

Ruby 1.06% Swift 98.94%

spalert's Introduction

Popup from Apple Music & Feedback in AppStore. Contains Done, Heart, Error and other. Supports Dark Mode and SwiftUI. I tried to recreate Apple's alerts as much as possible. You can find these alerts in the AppStore after feedback and after you add a song to your library in Apple Music.

For get alert from switch silent mode, check library SPIndicator.

Navigate

Installation

Ready for use on iOS 11+.

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

Once you have your Swift package set up, adding as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/ivanvorobei/SPAlert", .upToNextMajor(from: "4.2.0"))
]

CocoaPods:

CocoaPods is a dependency manager. For usage and installation instructions, visit their website. To integrate using CocoaPods, specify it in your Podfile:

pod 'SPAlert'

Manually

If you prefer not to use any of the dependency managers, you can integrate manually. Put Sources/SPAlert folder in your Xcode project. Make sure to enable Copy items if needed and Create groups.

Quick Start

For the best experience, I recommend presenting alerts by calling the class functions SPAlert. These functions are updated regularly and show the alerts as Apple way:

SPAlert.present(title: "Added to Library", preset: .done)

For using a custom image:

SPAlert.present(title: "Love", message: "We'll recommend more like this in For You", preset: .custom(UIImage.init(named: "heart")!))

For showing a simple text message:

SPAlert.present(message: "Something going wrong", haptic: .error)

Usage

Duration

To change the duration of present time, create an alert view and call present method with custom duration:

let alertView = SPAlertView(title: "Complete", preset: .done)
alertView.duration = 4
alertView.present()

If you don't want to dismiss alert in time, disable dismissInTime. After it, duration property will be ignored.

alertView.dismissInTime = false

In this case, you should dismiss the alert manually.

Dismiss

If you tap the alert, it will disappear. This can be disabled:

alertView.dismissByTap = false

Also, you can manually dismiss all alerts, simply call this:

SPAlert.dismiss()

Layout

For customise layout and margins, use layout property. You can manage margins for each side, icon size and space between image and titles:

alertView.layout.iconSize = .init(width: 24, height: 24)
alertView.layout.margins.top = 12
alertView.layout.spaceBetweenIconAndTitle = 8

Haptic

To manage haptic, you should pass it in present method:

alertView.present(duration: 1.5, haptic: .success, completion: nil)

You can remove duration and completion, because they have default values.

Spinner

I added the preset .spinner, to use it simply call this:

let alertView = SPAlertView(title: "Please, wait", preset: .spinner)
alertView.present()

By default this preset dismissInTime is disabled and the alert needs to be manually dismissed. You can do it only for one view or dismiss all alerts:

// For one alert
alertView.dismiss()

// For all alerts
SPAlert.dismiss()

Colors

For change color of icon, simple set tint color for any preset:

alertView.iconView?.tintColor = .systemRed

//If you set custom image, don't forget set rendering mode:
UIImage(systemName: "pencil.and.outline")!.withRenderingMode(.alwaysTemplate)

Global Appearance

Also you can change some default values for alerts. For example you can change default duration and corner radius for alert with next code:

SPAlertView.appearance().duration = 2
SPAlertView.appearance().cornerRadius = 12

It will apply to all alerts. I recommend setting it in the app delegate, but you can change it in runtime.

SwiftUI

Use like system alert only show message tips:

Button("Show alert") {
    showAlert = true
}.SPAlert(isPresent: $showAlert, message: "this is message only")

or show message, title, image and other configuration:

Button("Show alert") {
    showAlert = true
}.SPAlert(
    isPresent: $showAlert, 
    title: "Alert title", 
    message: "Alert message",
    duration: 2.0, 
    dismissOnTap: false, 
    preset: .custom(UIImage(systemName: "heart")!), 
    haptic: .success, 
    layout: .init(), 
    completion: {
        print("Alert is destory")
    })

Russian Community

Я веду телеграм-канал, там публикую новости и туториалы.
С проблемой помогут в чате.

Видео-туториалы выклыдываю на YouTube:

Tutorials on YouTube

spalert's People

Contributors

aniltaskiran avatar erjanmx avatar honqii avatar itsliamdowd avatar ivanvorobei avatar jillevdw avatar leeceny avatar swifthing avatar tijme avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.