Remove reference to view model in UIViewControllerRepresentable

This commit is contained in:
Justin Mazzocchi 2020-12-02 10:59:02 -08:00
parent b5f80237b0
commit a62c6d9781
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
4 changed files with 10 additions and 10 deletions

View file

@ -22,10 +22,10 @@ struct PreferencesView: View {
viewModel: .init(identification: identification))) viewModel: .init(identification: identification)))
} }
NavigationLink("preferences.muted-users", NavigationLink("preferences.muted-users",
destination: TableView(viewModel: viewModel.mutedUsersViewModel()) destination: TableView(viewModelClosure: viewModel.mutedUsersViewModel)
.navigationTitle(Text("preferences.muted-users"))) .navigationTitle(Text("preferences.muted-users")))
NavigationLink("preferences.blocked-users", NavigationLink("preferences.blocked-users",
destination: TableView(viewModel: viewModel.blockedUsersViewModel()) destination: TableView(viewModelClosure: viewModel.blockedUsersViewModel)
.navigationTitle(Text("preferences.blocked-users"))) .navigationTitle(Text("preferences.blocked-users")))
} }
Section(header: Text("preferences.app")) { Section(header: Text("preferences.app")) {

View file

@ -56,11 +56,11 @@ struct SecondaryNavigationView: View {
NavigationLink(destination: ListsView(viewModel: .init(identification: viewModel.identification))) { NavigationLink(destination: ListsView(viewModel: .init(identification: viewModel.identification))) {
Label("secondary-navigation.lists", systemImage: "scroll") Label("secondary-navigation.lists", systemImage: "scroll")
} }
NavigationLink(destination: TableView(viewModel: viewModel.favoritesViewModel()) NavigationLink(destination: TableView(viewModelClosure: viewModel.favoritesViewModel)
.navigationTitle(Text("favorites"))) { .navigationTitle(Text("favorites"))) {
Label("favorites", systemImage: "star") Label("favorites", systemImage: "star")
} }
NavigationLink(destination: TableView(viewModel: viewModel.bookmarksViewModel()) NavigationLink(destination: TableView(viewModelClosure: viewModel.bookmarksViewModel)
.navigationTitle(Text("bookmarks"))) { .navigationTitle(Text("bookmarks"))) {
Label("bookmarks", systemImage: "bookmark") Label("bookmarks", systemImage: "bookmark")
} }

View file

@ -62,7 +62,7 @@ private extension TabNavigationView {
func view(tab: NavigationViewModel.Tab) -> some View { func view(tab: NavigationViewModel.Tab) -> some View {
switch tab { switch tab {
case .timelines: case .timelines:
TableView(viewModel: viewModel.timelineViewModel) TableView { viewModel.timelineViewModel }
.id(viewModel.timeline.id) .id(viewModel.timeline.id)
.edgesIgnoringSafeArea(.all) .edgesIgnoringSafeArea(.all)
.navigationTitle(viewModel.timeline.title) .navigationTitle(viewModel.timeline.title)
@ -95,7 +95,7 @@ private extension TabNavigationView {
}) })
case .notifications: case .notifications:
if let notificationsViewModel = viewModel.notificationsViewModel { if let notificationsViewModel = viewModel.notificationsViewModel {
TableView(viewModel: notificationsViewModel) TableView { notificationsViewModel }
.id(tab) .id(tab)
.edgesIgnoringSafeArea(.all) .edgesIgnoringSafeArea(.all)
.navigationTitle("notifications") .navigationTitle("notifications")
@ -104,7 +104,7 @@ private extension TabNavigationView {
} }
case .messages: case .messages:
if let conversationsViewModel = viewModel.conversationsViewModel { if let conversationsViewModel = viewModel.conversationsViewModel {
TableView(viewModel: conversationsViewModel) TableView { conversationsViewModel }
.id(tab) .id(tab)
.edgesIgnoringSafeArea(.all) .edgesIgnoringSafeArea(.all)
.navigationTitle("messages") .navigationTitle("messages")

View file

@ -5,10 +5,10 @@ import ViewModels
struct TableView: UIViewControllerRepresentable { struct TableView: UIViewControllerRepresentable {
@EnvironmentObject var identification: Identification @EnvironmentObject var identification: Identification
let viewModel: CollectionViewModel let viewModelClosure: () -> CollectionViewModel
func makeUIViewController(context: Context) -> TableViewController { func makeUIViewController(context: Context) -> TableViewController {
TableViewController(viewModel: viewModel, identification: identification) TableViewController(viewModel: viewModelClosure(), identification: identification)
} }
func updateUIViewController(_ uiViewController: TableViewController, context: Context) { func updateUIViewController(_ uiViewController: TableViewController, context: Context) {
@ -21,7 +21,7 @@ import PreviewViewModels
struct StatusListView_Previews: PreviewProvider { struct StatusListView_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
TableView(viewModel: NavigationViewModel(identification: .preview).timelineViewModel) TableView { NavigationViewModel(identification: .preview).timelineViewModel }
} }
} }
#endif #endif