Post

Replies

Boosts

Views

Activity

Opening a sheet/modal after tapping on a SwiftUI List item in iOS 14+
I have a list (sourced from Core Data) where each row is tappable and it opens a sheet. I’m passing an Observable Object from the list to the view loaded within the Sheet/Modal. I struggled with this code when I wrote it during the early/buggy days of SwiftUI last June (2019) and eventually ended up storing an ID in the row's View, then doing a lookup at time of tap. This worked great in iOS13 (and continues to do so even in Xcode 12) and resolved issues I had been experiencing with sheets opening the first time but never again (or not being dismissible). With that said, this doesn't sound like the right way to go, partially confirmed by this not working in iOS 14. I can't seem to find a good example anywhere of how one is supposed to do this. List { ForEach (locationStore.locations) { location in LocationRow(location: location, showLocationDetailsModal: self.$showLocationDetailsModal, locationIDToShowDetails: self.$locationIDToShowDetails)                         }                     }         .sheet(isPresented: self.$showLocationDetailsModal, content: { LocationDetailView(location: self.locationStore.locations.first(where: {$0.id == self.locationIDToShowDetails})!) .environmentObject(self.locationStore) .environmentObject(self.applicationManager)      })
9
0
8.0k
Jun ’20