Swiftpack.co - tkoehlerlg/SwiftUI-AlertKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by tkoehlerlg.
tkoehlerlg/SwiftUI-AlertKit v0.4.0
An Alert-Kit for SwiftUI! For easy integration without minding any logic.
⭐️ 0
🕓 1 year ago
iOS macOS
.package(url: "https://github.com/tkoehlerlg/SwiftUI-AlertKit.git", from: "v0.4.0")

SwiftUI-AlertKit

An Alert-Kit for SwiftUI! For easy integration without minding any logic or design, but fully customizable! And I bet you love the animations!

🚀 Integration

You can either integrate this Package in your App-Project or in your Package.swift file if you're building a Package. Simply refer to the current version 0.4.0 and set it to next minor version.

🛠️ Use

This Project is focused on simple integration as well as easy maintaince. You simply set the GlobalAKAlertView around your ParentView and everything works right out of the Box!

GlobalAKAlertView(accentColor: .orange) {
    ParentView { }
}

You can easily modify most of the styles:

overlayBackground: ShapeStyle, alertBackground: ShapeStyle, accentColor: Color and textColor: Color

Or you create your own AlertStack

GlobalAKAlertView(
    overlayBackground: .ultraThinMaterial,
    textColor: .primary,
    alertStackView: { alertState in 
        AlertStackView { } 
    },
) {
    ParentView { }
}

Raising an Alert has never been easier!

Just set an optional AKAlert to the desired alert and it alerts the user immediately!

struct ChildView: View {
    @State var alert: AKAlert?

    var body: some View {
        Button("Button", action: {
            alert = .init(
                title: "This is an Error",
                message: "And this is an Error Message",
                primaryButton: .init(
                    title: "Okay",
                    style: .secondary,
                    action: { print("Okay!!") }
                )
            )
        })
        .alert($alert)
    }
}

Here a image of how an Alert looks like only set the accent color to orange:

Do you like The Composable Architecture? I do too!

We support the Composable Architecture right out of the Swift Package!

struct Child: ReducerProtocol {
    struct State: Equatable {
        var alert: ComposableAKAlert<Action>?
    }
    enum Action: Equatable {
        case alert(ComposableAKAlert<Action>?)
        case triggerAlert
        case alertTappedOkay
    }
    func reduce(into state: inout State, action: Action) -> EffectTask<Action> {
        switch action {
        case .alert(let newAlert):
            state.alert = newAlert
            return .none
        case .triggerAlert:
            state.alert = .init(
                title: "This is an Error",
                message: "And this is an Error Message",
                primaryButton: ComposableAKButton(
                    title: "Okay",
                    style: .secondary,
                    action: Action.alertTappedOkay
                )
            )
            return .none
        case .alertTappedOkay:
            print("Okay!!")
            return .none
        }
    }
}

After this you can simply use this alert in your ChildView like this:

struct ChildView: View {
    var store: StoreOf<Child>

    var body: some View {
        WithViewStore(store, observe: { $0 }) { viewStore in
            Button("Button", action: {
                viewStore.send(.triggerAlert)
            })
            .alert(viewStore.binding(
                get: \.alert,
                send: Child.Action.alert
            ), viewStore: viewStore)
        }
    }
}

This is all!

Hope you like the repository and please left a star!

GitHub

link
Stars: 0
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

0.3.10
1 year ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics