From 9a56d79d55b0054c94f4acce9267d17a598a2c02 Mon Sep 17 00:00:00 2001 From: Kirill Zyusko Date: Fri, 4 Nov 2022 20:38:44 +0400 Subject: [PATCH] fix: avoid usage of forced unwrapping (#95) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 📜 Description Added optional chaining instead of forced unwrapping. Fixes crash described in https://github.com/kirillzyusko/react-native-keyboard-controller/issues/93 ## 💡 Motivation and Context In fact it's not a fix and is more avoiding NPE rather than a full fix. But anyway, missing animation is better, than a crash of application 🤷‍♂️ ## 📢 Changelog ### iOS - avoid usage of forced unwrapping ## 🤔 How Has This Been Tested? Tested locally on: - iPhone 13 Pro (iOS 15.0); ## 📝 Checklist - [x] CI successfully passed --- ios/KeyboardMovementObserver.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/KeyboardMovementObserver.swift b/ios/KeyboardMovementObserver.swift index 417d7810a0..4faa210162 100644 --- a/ios/KeyboardMovementObserver.swift +++ b/ios/KeyboardMovementObserver.swift @@ -161,8 +161,8 @@ public class KeyboardMovementObserver: NSObject { return } - var keyboardFrameY = keyboardView!.layer.presentation()!.frame.origin.y - var keyboardWindowH = keyboardView!.window!.bounds.size.height + var keyboardFrameY = keyboardView?.layer.presentation()?.frame.origin.y ?? 0 + var keyboardWindowH = keyboardView?.window?.bounds.size.height ?? 0 var keyboardPosition = keyboardWindowH - keyboardFrameY if keyboardPosition == prevKeyboardPosition || keyboardFrameY == 0 {