Hi guys.
I'm new here.
Unfortunately, I couldn't find an answer related to present different views as modal in fullScreenCover based on the view type.
And I hope we will find the right way quickly =).
So the goal: I would like to show different views using the single fullScreenCover.
What I have:
2. Defined method that returns a required view
3. My ContentView looks as:
Here I would like to keep Binding property showModal to close my custom views.
But the main problem is -> my custom view isn't open.
I debugged code and I made sure the corresponding views return.
So what is the problem?
I'm new here.
Unfortunately, I couldn't find an answer related to present different views as modal in fullScreenCover based on the view type.
And I hope we will find the right way quickly =).
So the goal: I would like to show different views using the single fullScreenCover.
What I have:
I defined enum with possible view types.
Code Block language enum FullScreenType: Int, Identifiable { var id: Int { rawValue } case none case seasonDetails case topTimes }
2. Defined method that returns a required view
Code Block language func makeFullScreenContent(_ fullScreenType: FullScreenType) -> some View { return Group { switch fullScreenType { case .seasonDetails: SeasonDetailsView(selectedSeason: self.$season, showModal: $showModal) case .topTimes: TimesView(eventId: $eventId, showModal: $showModal) case .none: EmptyView() } } }
3. My ContentView looks as:
Code Block language struct ContentView: View { // some code // ... @State private var showModal = false @State private var fullScreenType: FullScreenType? = Optional.none var body: some View { VStack { // some stuff // ... if card.flipped { self.fullScreenType = .topTimes self.showModal.toggle() } else { self.fullScreenType = .seasonDetails self.showModal.toggle() } } } .fullScreenCover(item: $fullScreenType, content: { fullScreenType in makeFullScreenContent(fullScreenType) }) } }
Here I would like to keep Binding property showModal to close my custom views.
But the main problem is -> my custom view isn't open.
I debugged code and I made sure the corresponding views return.
So what is the problem?