Skip to content

Commit

Permalink
fix inset for favorites overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
brindy committed Oct 11, 2023
1 parent 58b749d commit 641ef76
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
40 changes: 38 additions & 2 deletions DuckDuckGo/FavoritesOverlay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ import Persistence
protocol FavoritesOverlayDelegate: AnyObject {

func favoritesOverlay(_ overlay: FavoritesOverlay, didSelect favorite: BookmarkEntity)
func favoritesOverlayDidRequestSearchBarRect() -> CGRect

}

class FavoritesOverlay: UIViewController {

struct Constants {
static let margin: CGFloat = 28
static let footerPadding: CGFloat = 50
static let toolbarHeight: CGFloat = 52
}

private let layout = UICollectionViewFlowLayout()
Expand All @@ -41,7 +44,12 @@ class FavoritesOverlay: UIViewController {
private var theme: Theme!

weak var delegate: FavoritesOverlayDelegate?


var isAddressBarAtBottom: Bool {
let searchBarRect = delegate?.favoritesOverlayDidRequestSearchBarRect() ?? .zero
return searchBarRect.minY > view.frame.midY
}

init(viewModel: FavoritesListInteracting) {
renderer = FavoritesHomeViewSectionRenderer(allowsEditing: false,
viewModel: viewModel)
Expand All @@ -66,6 +74,8 @@ class FavoritesOverlay: UIViewController {

renderer.install(into: self)

registerForKeyboardNotifications()

applyTheme(ThemeManager.shared.currentTheme)
}

Expand All @@ -81,7 +91,33 @@ class FavoritesOverlay: UIViewController {
collectionView.frame = view.bounds
collectionView.reloadData()
}
}

private func registerForKeyboardNotifications() {
NotificationCenter.default.addObserver(self,
selector: #selector(keyboardDidShow),
name: UIResponder.keyboardDidShowNotification,
object: nil)

NotificationCenter.default.addObserver(self,
selector: #selector(keyboardWillHide),
name: UIResponder.keyboardWillHideNotification,
object: nil)
}

@objc private func keyboardDidShow(notification: NSNotification) {
guard !AppWidthObserver.shared.isLargeWidth else { return }
guard let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return }
let keyboardSize = keyboardFrame.size
let bottomInset = isAddressBarAtBottom ? 0 : keyboardSize.height - Constants.toolbarHeight
collectionView.contentInset = UIEdgeInsets(top: 0.0, left: 0.0, bottom: bottomInset, right: 0.0)
}

@objc private func keyboardWillHide(notification: NSNotification) {
collectionView.contentInset = .zero
collectionView.scrollIndicatorInsets = .zero
}

}

extension FavoritesOverlay: FavoritesHomeViewSectionRendererDelegate {

Expand Down
15 changes: 5 additions & 10 deletions DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1002,16 +1002,6 @@ class MainViewController: UIViewController {
tabsBarController?.backgroundTabAdded()
}

func replaceToolbar(item target: UIBarButtonItem, with replacement: UIBarButtonItem) {
guard let items = viewCoordinator.toolbar.items else { return }

let newItems = items.compactMap({
$0 == target ? replacement : $0
})

viewCoordinator.toolbar.setItems(newItems, animated: false)
}

func newTab(reuseExisting: Bool = false, allowingKeyboard: Bool = true) {
if DaxDialogs.shared.shouldShowFireButtonPulse {
ViewHighlighter.hideAll()
Expand Down Expand Up @@ -1412,6 +1402,11 @@ extension MainViewController: FavoritesOverlayDelegate {
}
showHomeRowReminder()
}

func favoritesOverlayDidRequestSearchBarRect() -> CGRect {
searchBarRect
}

}

extension MainViewController: AutocompleteViewControllerDelegate {
Expand Down

0 comments on commit 641ef76

Please sign in to comment.