From 9aa53364c68dd38910685617feaf176ad6a35559 Mon Sep 17 00:00:00 2001 From: Serhii Kyrylenko Date: Sun, 8 Dec 2019 09:54:25 +0200 Subject: [PATCH 1/2] Fix for the crash due to missing environment Keyboard Observer object --- QBChat-MVVM/QBChat-MVVM/View/ChatList/ChatListView.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/QBChat-MVVM/QBChat-MVVM/View/ChatList/ChatListView.swift b/QBChat-MVVM/QBChat-MVVM/View/ChatList/ChatListView.swift index 9449f84..ab83b36 100644 --- a/QBChat-MVVM/QBChat-MVVM/View/ChatList/ChatListView.swift +++ b/QBChat-MVVM/QBChat-MVVM/View/ChatList/ChatListView.swift @@ -26,8 +26,10 @@ struct ChatListView: View { var body: some View { NavigationView { List(viewModel.chats) { viewModel in - NavigationLink(destination: ChatDetailView().environmentObject(viewModel)) { - ChatCell(chat: viewModel.state.chat) + NavigationLink(destination: ChatDetailView() + .environmentObject(viewModel) + .environmentObject(KeyboardObserver.shared)) { + ChatCell(chat: viewModel.state.chat) } } .navigationBarTitle("Chats") From cc22878444c2b25399623f6ee2bb36289379226e Mon Sep 17 00:00:00 2001 From: Serhii Kyrylenko Date: Sun, 8 Dec 2019 16:17:13 +0200 Subject: [PATCH 2/2] KeyboardObserver injection moved to the root ContentView for wider usage in ongoing views --- QBChat-MVVM/QBChat-MVVM/Common/SceneDelegate.swift | 1 + QBChat-MVVM/QBChat-MVVM/View/ChatList/ChatListView.swift | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/QBChat-MVVM/QBChat-MVVM/Common/SceneDelegate.swift b/QBChat-MVVM/QBChat-MVVM/Common/SceneDelegate.swift index d9d3f62..70a2e68 100644 --- a/QBChat-MVVM/QBChat-MVVM/Common/SceneDelegate.swift +++ b/QBChat-MVVM/QBChat-MVVM/Common/SceneDelegate.swift @@ -24,6 +24,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { let viewModel = AnyViewModel(ChatListViewModel(chatService: chatService)) let contentView = ChatListView() .environmentObject(viewModel) + .environmentObject(KeyboardObserver.shared) // Use a UIHostingController as window root view controller. if let windowScene = scene as? UIWindowScene { diff --git a/QBChat-MVVM/QBChat-MVVM/View/ChatList/ChatListView.swift b/QBChat-MVVM/QBChat-MVVM/View/ChatList/ChatListView.swift index ab83b36..9449f84 100644 --- a/QBChat-MVVM/QBChat-MVVM/View/ChatList/ChatListView.swift +++ b/QBChat-MVVM/QBChat-MVVM/View/ChatList/ChatListView.swift @@ -26,10 +26,8 @@ struct ChatListView: View { var body: some View { NavigationView { List(viewModel.chats) { viewModel in - NavigationLink(destination: ChatDetailView() - .environmentObject(viewModel) - .environmentObject(KeyboardObserver.shared)) { - ChatCell(chat: viewModel.state.chat) + NavigationLink(destination: ChatDetailView().environmentObject(viewModel)) { + ChatCell(chat: viewModel.state.chat) } } .navigationBarTitle("Chats")