From 787673fa34c8d009c9f70dca4a338a75cdf64eef Mon Sep 17 00:00:00 2001 From: Sophia Lee Date: Tue, 5 Dec 2023 13:10:36 -0800 Subject: [PATCH] Fixing keyboard support in drawers (#1938) (cherry picked from commit 8fd371881fd84938e44eb774963873261d203511) --- ios/FluentUI/Drawer/DrawerPresentationController.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ios/FluentUI/Drawer/DrawerPresentationController.swift b/ios/FluentUI/Drawer/DrawerPresentationController.swift index dcd5d1a014..4affeb871b 100644 --- a/ios/FluentUI/Drawer/DrawerPresentationController.swift +++ b/ios/FluentUI/Drawer/DrawerPresentationController.swift @@ -225,7 +225,7 @@ class DrawerPresentationController: UIPresentationController { } case .up: if actualPresentationOrigin == containerView.bounds.maxY { - return containerView.safeAreaInsets.bottom + keyboardHeight + return keyboardHeight == 0 ? containerView.safeAreaInsets.bottom : keyboardHeight } case .fromLeading: if actualPresentationOrigin == containerView.bounds.minX { @@ -344,6 +344,9 @@ class DrawerPresentationController: UIPresentationController { } private func frameForContentView(in bounds: CGRect) -> CGRect { + guard let containerView = containerView else { + return .zero + } var contentFrame = bounds.inset(by: marginsForContentView()) var contentSize = presentedViewController.preferredContentSize @@ -380,7 +383,8 @@ class DrawerPresentationController: UIPresentationController { contentFrame.origin.x += (contentFrame.width - contentSize.width) / 2 if presentationDirection == .up { - contentFrame.origin.y = contentFrame.maxY - contentSize.height + contentFrame.origin.y = keyboardHeight != 0 ? max(landscapeMode ? 0 : sourceViewController.view.safeAreaInsets.top, + containerView.frame.maxY - keyboardHeight - contentSize.height) : contentFrame.maxY - contentSize.height } } else { if actualPresentationOffset == 0 { @@ -510,7 +514,7 @@ class DrawerPresentationController: UIPresentationController { keyboardAnimationDuration = (notificationInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue keyboardFrame = containerView.convert(keyboardFrame, from: nil) - keyboardHeight = max(0, containerView.bounds.maxY - containerView.safeAreaInsets.bottom - keyboardFrame.minY) + keyboardHeight = max(0, containerView.bounds.maxY - keyboardFrame.minY) } }