SwiftUI toolbar button item issue

526 views Asked by At

I have a ToolbarItemGroup with a navigation link and a button. With the current setup when I hit "Add" it goes to the AddNewTripView just fine but when I hit the back button (to return to the list view) it goes back to the previous view and then jumps right back to the AddNewTripView.

If I remove the Edit button it works fine. Is this a bug in SwiftUI or am I doing something wrong?

var body: some View {
        ScrollView { }
        .onAppear {
            tripListViewModel.getAllTrips()
        }
        .navigationTitle("Trips")
        .navigationBarTitleDisplayMode(.inline)
        .toolbar {
            ToolbarItemGroup(placement: .navigationBarTrailing) {
                NavigationLink(destination: AddNewTripView(repo: repo)) {
                    Text("Add")
                }
                Button(action: { isEditing.toggle() }) {
                    Text(isEditing ? "Done" : "Delete")
                        .foregroundColor(.primary)
                }
            }
        }
}
0

There are 0 answers