freshOS / KeyboardLayoutGuide

⌨️ KeyboardLayoutGuide, back from when it didn't exist.
MIT License
1.19k stars 60 forks source link

fix: support formSheet modal and floating keyboard #43

Open toshi0383 opened 2 years ago

toshi0383 commented 2 years ago

fixes: https://github.com/freshOS/KeyboardLayoutGuide/issues/33 fixes: https://github.com/freshOS/KeyboardLayoutGuide/issues/37

It turns out that formSheet automatically adjusts its position when keyboard is shown. So I needed to fallback to use keyboardDidChangeFrameNotification instead of keyboardWillChangeFrameNotification in this use case. This causes animation delay, but otherwise I couldn't calculate correct keyboardHeight inside formSheet.

https://user-images.githubusercontent.com/6007952/198422164-f36c506f-72d9-4816-96db-036baa8817e3.mp4

Usage is simple enough. Just set Keyboard.shared.presentedViewController when you know what you're doing.

Keyboard.shared.presentedViewController = self
vStack.bottomAnchor.constraint(lessThanOrEqualTo: view.keyboardLayoutGuideNoSafeArea.topAnchor).isActive = true