From 76a8cb36972bc9e9b8899f7e954e1eea96c5f735 Mon Sep 17 00:00:00 2001 From: Peter Paulis Date: Thu, 3 Feb 2022 16:08:11 +0100 Subject: [PATCH 1/2] Adding the option to not-animate/animate the selection When opening the menu, you want to have the option already displayed (and not displayed and than scroll to as currently), therefor the option animated = false is better... this is a non-breaking change --- DropDown/src/DropDown.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DropDown/src/DropDown.swift b/DropDown/src/DropDown.swift index f41e8ddd..3239015c 100644 --- a/DropDown/src/DropDown.swift +++ b/DropDown/src/DropDown.swift @@ -973,10 +973,10 @@ extension DropDown { } /// (Pre)selects a row at a certain index. - public func selectRow(at index: Index?, scrollPosition: UITableView.ScrollPosition = .none) { + public func selectRow(at index: Index?, scrollPosition: UITableView.ScrollPosition = .none, animated: Bool = true) { if let index = index { tableView.selectRow( - at: IndexPath(row: index, section: 0), animated: true, scrollPosition: scrollPosition + at: IndexPath(row: index, section: 0), animated: animated, scrollPosition: scrollPosition ) selectedRowIndices.insert(index) } else { From 600ac57fd26ab690af3b8179db46ae9437279573 Mon Sep 17 00:00:00 2001 From: Peter Paulis Date: Mon, 26 Sep 2022 12:41:56 +0200 Subject: [PATCH 2/2] Improving the .top display, respecting the safeArea margins and keyboard - Previously, when using .top, the bottom was not handled, but in case you are using topOffset to open the menu offseted, the menu could have been opened offscreen... this handles the situation - added support for respecting the safeArea, as the 20 constant was outdated --- DropDown/src/DropDown.swift | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/DropDown/src/DropDown.swift b/DropDown/src/DropDown.swift index 3239015c..518e15cf 100644 --- a/DropDown/src/DropDown.swift +++ b/DropDown/src/DropDown.swift @@ -749,13 +749,36 @@ extension DropDown { let x = anchorViewX + topOffset.x var y = (anchorViewMaxY + topOffset.y) - tableHeight - let windowY = window.bounds.minY + DPDConstant.UI.HeightPadding + var windowY = window.bounds.minY + if #available(iOS 11.0, *) { + windowY += window.safeAreaInsets.top + } else { + windowY += DPDConstant.UI.HeightPadding + } + + if y < windowY { + offscreenHeight = abs(y - windowY) + y = windowY + } else { + let maxY = y + tableHeight + + var windowMaxY = window.bounds.maxY - offsetFromWindowBottom + if #available(iOS 11.0, *) { + windowMaxY -= window.safeAreaInsets.bottom + } else { + windowMaxY -= DPDConstant.UI.HeightPadding + } - if y < windowY { - offscreenHeight = abs(y - windowY) - y = windowY + let keyboardListener = KeyboardListener.sharedInstance + let keyboardMinY = keyboardListener.keyboardFrame.minY - DPDConstant.UI.HeightPadding + + if keyboardListener.isVisible && maxY > keyboardMinY { + offscreenHeight = abs(maxY - keyboardMinY) + } else if maxY > windowMaxY { + offscreenHeight = abs(maxY - windowMaxY) + } } - + let width = self.width ?? (anchorView?.plainView.bounds.width ?? fittingWidth()) - topOffset.x return (x, y, width, offscreenHeight)