From 91ff9a24568ffffdaeb2eb4b5ed539de0af0463c Mon Sep 17 00:00:00 2001
From: Bruno Muniz Azevedo Filho <bruno@elixxir.io>
Date: Fri, 26 Aug 2022 21:24:23 -0300
Subject: [PATCH] Fixes retrieving key window crash

---
 .../ChatFeature/Controllers/SingleChatController.swift | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/Sources/ChatFeature/Controllers/SingleChatController.swift b/Sources/ChatFeature/Controllers/SingleChatController.swift
index 91aa66ec..b8d8b770 100644
--- a/Sources/ChatFeature/Controllers/SingleChatController.swift
+++ b/Sources/ChatFeature/Controllers/SingleChatController.swift
@@ -530,12 +530,10 @@ extension SingleChatController: KeyboardListenerDelegate {
     }
 
     func keyboardWillChangeFrame(info: KeyboardInfo) {
-        let keyWindow: UIWindow? = UIApplication.shared.connectedScenes
-            .filter { $0.activationState == .foregroundActive }
-            .compactMap { $0 as? UIWindowScene }
-            .first?
-            .windows
-            .first(where: \.isKeyWindow)
+        let keyWindow = UIApplication.shared
+            .connectedScenes
+            .flatMap { ($0 as? UIWindowScene)?.windows ?? [] }
+            .first { $0.isKeyWindow }
 
         guard let keyWindow = keyWindow else {
             fatalError("[keyboardWillChangeFrame]: Couldn't get key window")
-- 
GitLab