sparrowcode / AlertKit

Native alert from Apple Music & Feedback. Contains Done, Heart & Message and other presets.
https://sparrowcode.io/frameworks
MIT License
2.33k stars 131 forks source link

Loading View #21

Closed PedroCavaleiro closed 3 years ago

PedroCavaleiro commented 4 years ago

Hi,

I suggested a Loading View a few months back and you pointed me to this repo mlouli/SPAlert

I grabbed his changes but also made a few of my own

you can show a alert in a simple yet fast way

let alert = SPAlert.presentLoader(message: "Loading...")
alert.dismis()

If you want using the timeout it's also possible

let _ = SPAlert.presentLoader(message: "Loading...", timeout: 5)

by default it makes the loading view as a rectangle, this is a preference of my own, but you may disable this option by

let loadingView = SPAlertView(loadingMessage = "Loading...")
loadingView.makeLoadingViewRectangular = false
loadingView.present()

this way it will use the normal calculations.

I also updated the README.md to include this changes.

This library was tested in SwiftUI and found no errors

ivanvorobei commented 4 years ago

Thanks for changes! You solve many problems. I soon check it. Thanks!

PedroCavaleiro commented 4 years ago

It's now possible to change the foreground color and made a small change on the initialization of the activity view

let alertWithDismiss = SPAlertView(loadingMessage: "Loading...")
let alertWithTimeout = SPAlertView(loadingMessage: "Loading...", timeout: 3)

alertWithDismiss.foregroundColor = UIColor.white

If no color is passed it uses the default check the private var foregroundColorDefault: UIColor

PedroCavaleiro commented 4 years ago

It's now possible to add a blur to the views under the alert.

By default the blur is disabled for the alerts and enabled for the loading views

let alert = SPAlertView(loadingMessage: "Loading...")
alert.blurBackground = false

In case of the loading views you can disable on the initialization

let alert = SPAlertView(loadingMessage: "Loading...", blurBackground: false)
kuwait commented 4 years ago

Looks very nice! waiting on this as well asap!

PedroCavaleiro commented 4 years ago

As I'm also using this for an app that supports macOS Catalyst, this would give me a warning, to suppress the warning I added the following code.

public var keyWindow: UIView {
        if #available(iOS 13, macCatalyst 13, *) {
            return UIApplication.shared.connectedScenes
                .filter({$0.activationState == .foregroundActive})
                .map({$0 as? UIWindowScene})
                .compactMap({$0})
                .first?.windows
                .filter({$0.isKeyWindow}).first ?? UIWindow()
        } else {
            return (UIApplication.shared.keyWindow ?? UIWindow())
        }
    }

Allowing the newest versions of iOS, and macCatalyst to work but also older versions will still work

ivanvorobei commented 3 years ago

Hi! Sorry for big delay. I am open talk about loading if its still need.