AlertKit icon indicating copy to clipboard operation
AlertKit copied to clipboard

Alert blinks when navigate to another view

Open dr-star opened this issue 1 year ago • 0 comments

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

dr-star avatar Jun 21 '24 10:06 dr-star