Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI navigation bar title and items does not disappear when swiping back fails

enter image description here

The problem is that the title and the item of the navigation bar does not disappear which is an unexpected behaviour.

struct DestinationView: View {

@State private var showingActionSheet = false

var body: some View {
    Text("DestinationView")
        .padding(.top, 100)
        .navigationBarTitle(Text("Destination"), displayMode: .inline)
        .navigationBarItems(trailing: Button(action: {
            print("tapped")
        }, label: {
            Text("second")
        }))
        .actionSheet(isPresented: self.$showingActionSheet) { () -> ActionSheet in
            ActionSheet(title: Text("Settings"), message: nil, buttons: [
                .default(Text("Delete"), action: {
                }),
                .cancel()
            ])
        }

}

}
like image 669
Viktor Maric Avatar asked Mar 28 '20 01:03

Viktor Maric


1 Answers

The problem is that the .navigationBarTitle(), .navigationBarItems() modifiers and the .actionSheet() modifier are under each other in code. (But it can be the .alert() or the .overlay() modifiers as well instead of .actionSheet())

The solution in this case:

struct DestinationView: View {

@State private var showingActionSheet = false

var body: some View {

    List {
        Text("DestinationView")
            .padding(.top, 100)
            .navigationBarTitle(Text("Destination"), displayMode: .inline)
            .navigationBarItems(trailing: Button(action: {
                print("tapped")
            }, label: {
                Text("second")
            }))
    }
    .actionSheet(isPresented: self.$showingActionSheet) { () -> ActionSheet in
        ActionSheet(title: Text("Settings"), message: nil, buttons: [
            .default(Text("Delete"), action: {
            }),
            .cancel()
        ])
    }
}
}
like image 177
Viktor Maric Avatar answered Oct 16 '22 01:10

Viktor Maric