Skip to content

Latest commit

 

History

History
111 lines (105 loc) · 3.45 KB

README.md

File metadata and controls

111 lines (105 loc) · 3.45 KB

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!