mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-08 00:27:42 +00:00
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:
commit
400efd9df4
1 changed files with 17 additions and 7 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue