AlertKit
AlertKit copied to clipboard
Alert blinks when navigate to another view
Given my view
import SwiftUI
import AlertKit
struct CreateRewardView: View {
@StateObject var viewModel: CreateRewardViewModel = CreateRewardViewModel()
@Environment(\.dismiss) private var dismiss
var body: some View {
VStack {
...
}
.toolbar {
ToolbarItem(placement: .confirmationAction) {
Button("Save", action: {
Task {
await viewModel.save()
dismiss()
}
})
}
}
.alert(isPresent: $viewModel.showCreatedAlert, view: viewModel.createdAlert)
}
}
When the user clicks on "Save" button I showCreatedAlert becomes true so the alert is shown.
The problem is that a strange behavior happens when dismiss is triggered. The alert appears/disappears multiple times. Am I doing something wrong?
https://github.com/sparrowcode/AlertKit/assets/33574414/98af653b-d376-4709-8e78-851f7a260cdd