Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions DropDown/src/DropDown.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -973,10 +996,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 {
Expand Down