From dff4b8d990a40216bfbd9d0ba3ded84cbe47468c Mon Sep 17 00:00:00 2001 From: hn Date: Fri, 4 Mar 2022 13:14:53 +0900 Subject: [PATCH] fix screen freeze bug when keyboard is shown and textfield doesn't move --- ios/Classes/InAppWebView/InAppWebView.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ios/Classes/InAppWebView/InAppWebView.swift b/ios/Classes/InAppWebView/InAppWebView.swift index f49fcef7d..e50a241a1 100755 --- a/ios/Classes/InAppWebView/InAppWebView.swift +++ b/ios/Classes/InAppWebView/InAppWebView.swift @@ -136,6 +136,12 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi return result as? UILongPressGestureRecognizer } + @objc private func keyboardDidAppear(_ notification: Notification) { + guard let keyboardFrame = (notification.userInfo?["UIKeyboardFrameEndUserInfoKey"] as? NSValue)?.cgRectValue else { return } + scrollView.contentInset.bottom = keyboardFrame.height + } + + @objc func longPressGestureDetected(_ sender: UIGestureRecognizer) { if sender.state == .cancelled { return @@ -300,6 +306,12 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavi options: [.new, .old], context: nil) + NotificationCenter.default.addObserver( + self, + selector: #selector(keyboardDidAppear(_:)), + name: UIResponder.keyboardDidShowNotification, + object: nil) + NotificationCenter.default.addObserver( self, selector: #selector(onCreateContextMenu),