From 9bfb4f0be566fbe1a493fdafe6c8222b4c0c3732 Mon Sep 17 00:00:00 2001 From: sgschantz Date: Tue, 9 Jan 2024 15:24:29 +0700 Subject: [PATCH] use safe area to position Keyman menu correctly --- .../MainViewController.swift | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/ios/keyman/Keyman/Keyman/Classes/MainViewController/MainViewController.swift b/ios/keyman/Keyman/Keyman/Classes/MainViewController/MainViewController.swift index 56673bfa3f..b8ebca5117 100644 --- a/ios/keyman/Keyman/Keyman/Classes/MainViewController/MainViewController.swift +++ b/ios/keyman/Keyman/Keyman/Classes/MainViewController/MainViewController.swift @@ -940,18 +940,28 @@ class MainViewController: UIViewController, TextViewDelegate, UIActionSheetDeleg wasKeyboardVisible = textView.isFirstResponder textView.dismissKeyboard() - let w: CGFloat = 160 - let h: CGFloat = 44 - let x: CGFloat = navBarWidth() - w - let y: CGFloat = AppDelegate.statusBarHeight() + navBarHeight() - - let dropDownList = DropDownListView(listItems: dropdownItems, itemSize: CGSize(width: w, height: h), - position: CGPoint(x: x, y: y)) + let menuRect: CGRect = self.calculateDropDownMenuRect() + let dropDownList = DropDownListView(listItems: dropdownItems, itemSize: menuRect.size, position: menuRect.origin) dropDownList.tag = dropDownListTag navigationController?.view?.addSubview(dropDownList) } + /** + * Calculates coordinates of Keyman app dropdown menu + * takes into account safearea so that menu does display over iPhone notch when + * rotated to landscape (issue #8168) + */ + private func calculateDropDownMenuRect() -> CGRect { + let rightInset: CGFloat? = self.view.window?.safeAreaInsets.right + let width: CGFloat = 160 + let height: CGFloat = 44 + let x: CGFloat = navBarWidth() - width - (rightInset ?? 0) + let y: CGFloat = AppDelegate.statusBarHeight() + navBarHeight() + let menuRect = CGRect(x: x, y: y, width: width, height: height) + return menuRect + } + private func dismissDropDownMenu() -> Bool { let view = navigationController?.view?.viewWithTag(dropDownListTag) if view != nil && wasKeyboardVisible {