Hi guys.
I have a question related to the next behavior.
I have ContentView with a list of views where the corresponding view models are passed. The user can click by some view. At the moment full-screen modal dialog will be shown according to the passed type. It's fine.
At some time my view models are being updated and the whole ContentView will be reloaded. The problem is: fullScreenCover is called and ChildEventView is recreated. How to prevent recreating ChildEventView?
I have a question related to the next behavior.
I have ContentView with a list of views where the corresponding view models are passed. The user can click by some view. At the moment full-screen modal dialog will be shown according to the passed type. It's fine.
At some time my view models are being updated and the whole ContentView will be reloaded. The problem is: fullScreenCover is called and ChildEventView is recreated. How to prevent recreating ChildEventView?
Code Block language struct ContentView: View { @ObservedObject private var eventListViewModel = EventListViewModel() @State private var fullScreenType: FullScreenType? /* some stuff */ var body: some View { ScrollView { LazyVStack { ForEach(eventListViewModel.cardStates.indices, id: \.self) { index in let eventVM = eventListViewModel.eventVMs[index] EventCardView(eventViewModel: eventVM, eventId: $selectedEvent.eventId) { self.fullScreenType = .type1 } /* some other views */ } } } .fullScreenCover(item: $fullScreenType, onDismiss: { self.fullScreenType = nil }, content: { fullScreenType in switch fullScreenType { case .type1: return ChildEventView(selectedEvent.eventId).eraseToAnyView() /* some other cases */ } }) } }