swiftuiswiftui-navigationlinkswiftui-sheet

Problem in view with sheet, button cannot be access


I created a view that has the sheet element and I disabled the option for it to be dismissed, but this led to the problem of the back button for the other view not being accessible.

image of my view

import SwiftUI

struct PackDetailView: View {
    @State private var isShowingSheet = true
    var playlist: PlaylistModel

    var body: some View {
        Image(playlist.images)
            .resizable()
            .aspectRatio(contentMode: .fill)
            .ignoresSafeArea(.all)
                    
        .sheet(isPresented: $isShowingSheet) {
            ZStack {
                Color.primaryApp.ignoresSafeArea(.all)
                
                Text("\(playlist.title)")
            }
            .presentationDetents([.height(250), .height(720)])
            .presentationDragIndicator(.visible)
            .interactiveDismissDisabled(true)       
        }
    }
}

This is the code for this part of the view.


Solution

  • By default, sheets are modal which means that all interaction with the sheet behind is disabled.

    You can alter this behaviour with the presentationBackgroundInteraction modifier (see https://developer.apple.com/documentation/swiftui/view/presentationbackgroundinteraction(_:)).

    If you add .presentationBackgroundInteraction(.enabled) then all UI elements, including the back button, will be useable.