fullScreenCover is being dismissed when rotating view

229 Views Asked by At

I have a manga series detail view that displays the series information and all of the chapters. Each chapter you can tap on to read and it will present the reader with a fullScreenCover. When rotating the reader to any orientation it dismisses back to the manga series detail view when it shouldn't. Here is some pseudo code for the manga series view:

struct MangaSeriesView: View {
    @StateObject var seriesViewModel = SeriesViewModel()
    
    var body: some View {
        ScrollView {
            VStack {
                TopDetailView()
                
                ChapterListView()
            }
        }
        .onAppear {
            fetchSeriesDetails()
        }
    }
}
struct ChapterListView: View {
    @EnvironmentObject var seriesViewModel: seriesViewModel
    
    var body: some View {
        LazyVStack {
            ForEach(seriesViewModel.chapters, id: \.self) { manga in
                ChapterCellView(manga: manga, series: seriesViewModel.series)
            }
        }
    }
}
struct ChapterCellView: View {
    let manga: Manga
    let series: Series
    @State var isPresented = false
    
    var body: some View {
        HStack {
            Text("Chapter number")
            
            Button {
                isPresented = true
            } label: {
                Text("Read")
            }

            Button {
                
            } label: {
                Text("Download")
            }
        }
        .fullScreenCover(isPresented: $isPresented) {
            ReaderView(manga: manga, series: series)
        }
    }
}

After debugging for a while the only thing that solves this issue was removing the LazyVStack in the ChapterListView. But some series can have hundreds of chapters so I need the ForEach to be lazy for the scrolling performance. Does anybody know why this LazyVStack would cause the fullScreenCover to dismiss when rotating the ReaderView? There isn't any logic in the ReaderView that calls it to dismiss.

0

There are 0 best solutions below