From 04d3e833cace5d1e2db49e601e5606cf5b2a4ca6 Mon Sep 17 00:00:00 2001 From: Martin Andonoski Date: Fri, 8 Oct 2021 10:58:18 +0200 Subject: [PATCH] Make window optional in ViewPortState prevent crashes in iOS 15 (#172) --- Form/ViewPortEvent.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Form/ViewPortEvent.swift b/Form/ViewPortEvent.swift index 1e54b25..6fe681d 100644 --- a/Form/ViewPortEvent.swift +++ b/Form/ViewPortEvent.swift @@ -48,7 +48,7 @@ public extension UIView { private class ViewPortState { weak var window: UIWindow? // Not keeping strong reference to the window to avoid UIWindow leaks let bag = DisposeBag() - init(window: UIWindow) { + init(window: UIWindow?) { self.window = window bag += Form.keyboardSignal().onValue { _ in } // Make sure to setup listener so keyboardFrame will be updated } @@ -73,7 +73,7 @@ private extension UIView { } let app = UIApplication.shared - let window = self.window ?? (self as? UIWindow) ?? app.keyWindow ?? app.windows.first! + let window = self.window ?? (self as? UIWindow) ?? app.keyWindow ?? app.windows.first return associatedValue(forKey: &viewPortKey, initial: ViewPortState(window: window)) } }