Post

Replies

Boosts

Views

Created

ChildView in FullScreenCover is recreated every time if ContentView is updated
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? 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 */ 						} 				}) 		} }
2
0
1.8k
Jan ’21
ChildView in FullScreenCover is recreated every time if ContentView is updated
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? 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 */ 						} 				}) 		} }
Replies
2
Boosts
0
Views
1.8k
Activity
Jan ’21