I am working on a video streaming service, the app allows users to select a video from the home page, this opens up a sheet that displays the video, some information, and other videos in the playlist. Users are able to tap one of the other videos in the playlist, and it opens a new video sheet over the current page. The user can continue to open up videos this way, causing a stack of sheets. I want the user to be able to dismiss one sheet, and have them all disappear. Here is a very basic mock up of how the app works
My idea was that setting the original boolean to false would hide the original sheet, which would also hide the rest of the sheets. If I only have 2 sheets open, this works, and dismissing the second sheet will also dismiss the first. If I have 3 or more sheets open, it will dismiss all sheets except for the first. I am relatively new to Swiftui so I am not sure if this is the way I should be handling the sheet dismissal. I would appreciate any tips on fixing this or any idea for a different way to handle the dismissal, thanks in advance!
Code Block struct ContentView: View { @State var isShowing=false var body: some View { VStack{ Button("Show Modal"){isShowing=true} .sheet(isPresented: $isShowing){ modal_sheet(isShowing: $isShowing) } } } }
Code Block struct modal_sheet: View { @Binding var isShowing : Bool @State var showingNext = false var body: some View { VStack{ Button("Next Modal"){showingNext.toggle()} .sheet(isPresented: $showingNext, onDismiss: {isShowing=false}){ modal_sheet(isShowing: $isShowing) } } } }
My idea was that setting the original boolean to false would hide the original sheet, which would also hide the rest of the sheets. If I only have 2 sheets open, this works, and dismissing the second sheet will also dismiss the first. If I have 3 or more sheets open, it will dismiss all sheets except for the first. I am relatively new to Swiftui so I am not sure if this is the way I should be handling the sheet dismissal. I would appreciate any tips on fixing this or any idea for a different way to handle the dismissal, thanks in advance!