An Alert-Kit for SwiftUI! For easy integration without minding any logic or design, but fully customizable! And I bet you love the animations!
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.
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 { }
}
overlayBackground: ShapeStyle
,
alertBackground: ShapeStyle
,
accentColor: Color
and
textColor: Color
GlobalAKAlertView(
overlayBackground: .ultraThinMaterial,
textColor: .primary,
alertStackView: { alertState in
AlertStackView { }
},
) {
ParentView { }
}
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:
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!