Merge pull request #10339 from keymanapp/fix/ios/8168-reposition-menu

fix(ios): use safe area to position Keyman menu correctly
This commit is contained in:
Shawn Schantz 2024-01-12 14:24:55 +07:00 committed by GitHub
commit 400efd9df4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 {