Skip to content

Commit

Permalink
apply content inset when keyboard is visible
Browse files Browse the repository at this point in the history
  • Loading branch information
brindy committed Mar 12, 2024
1 parent e175c15 commit fd64707
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 42 deletions.
31 changes: 1 addition & 30 deletions DuckDuckGo/AutocompleteViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,7 @@ class AutocompleteViewController: UIViewController {

func willDismiss(with query: String) {
guard selectedItem != -1, selectedItem < suggestions.count else { return }

// TODO fire pixels
// let suggestion = suggestions[selectedItem]
// if let url = suggestion.url {
// if query == url.absoluteString {
// firePixel(selectedSuggestion: suggestion)
// }
// } else if query == suggestion.suggestion {
// firePixel(selectedSuggestion: suggestion)
// }
// TODO fire pixel
}

@IBAction func onPlusButtonPressed(_ button: UIButton) {
Expand Down Expand Up @@ -268,31 +259,11 @@ extension AutocompleteViewController: UITableViewDataSource {
return receivedResponse ? max(Constants.minItems, suggestions.count) : 0
}

// TODO fire pixel
private func firePixel(selectedSuggestion: Suggestion) {
// let resultsIncludeBookmarks: Bool
// if let firstSuggestion = suggestions.first {
// resultsIncludeBookmarks = firstSuggestion.source == .local
// } else {
// resultsIncludeBookmarks = false
// }

// let params = [PixelParameters.autocompleteBookmarkCapable: bookmarksSearch.hasData ? "true" : "false",
// PixelParameters.autocompleteIncludedLocalResults: resultsIncludeBookmarks ? "true" : "false"]

// if selectedSuggestion.source == .local {
// Pixel.fire(pixel: .autocompleteSelectedLocal, withAdditionalParameters: params)
// } else {
// Pixel.fire(pixel: .autocompleteSelectedRemote, withAdditionalParameters: params)
// }

}
}

extension AutocompleteViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let suggestion = suggestions[indexPath.row]
firePixel(selectedSuggestion: suggestion)
delegate?.autocomplete(selectedSuggestion: suggestion)
}
}
Expand Down
11 changes: 1 addition & 10 deletions DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -565,16 +565,7 @@ class MainViewController: UIViewController {
findInPageBottomLayoutConstraint.constant = height
keyboardHeight = height

if let suggestionsTray = suggestionTrayController {
let suggestionsFrameInView = suggestionsTray.view.convert(suggestionsTray.contentFrame, to: view)

let overflow = suggestionsFrameInView.size.height + suggestionsFrameInView.origin.y - keyboardFrameInView.origin.y + 10
if overflow > 0 {
suggestionTrayController?.applyContentInset(UIEdgeInsets(top: 0, left: 0, bottom: overflow, right: 0))
} else {
suggestionTrayController?.applyContentInset(.zero)
}
}
suggestionTrayController?.applyContentInset(.init(top: 0, left: 0, bottom: keyboardHeight, right: 0))

let y = self.view.frame.height - height
let frame = self.findInPageView.frame
Expand Down
6 changes: 4 additions & 2 deletions DuckDuckGo/SuggestionTrayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ class SuggestionTrayViewController: UIViewController {
let controller = FavoritesOverlay(viewModel: favoritesModel)
controller.delegate = favoritesOverlayDelegate
install(controller: controller, completion: onInstall)
controller.collectionView.contentInset = self.contentInsets
favoritesOverlay = controller
}

Expand All @@ -243,6 +244,7 @@ class SuggestionTrayViewController: UIViewController {
private func installAutocompleteSuggestions() {
let controller = AutocompleteViewController.loadFromStoryboard(bookmarksDatabase: bookmarksDatabase, historyCoordinator: historyCoordinator)
install(controller: controller)
controller.tableView.contentInset = contentInsets
controller.delegate = autocompleteDelegate
controller.presentationDelegate = self
autocompleteController = controller
Expand Down Expand Up @@ -275,9 +277,9 @@ class SuggestionTrayViewController: UIViewController {
})
}

var contentInsets = UIEdgeInsets.zero
func applyContentInset(_ inset: UIEdgeInsets) {
autocompleteController?.tableView.contentInset = inset
favoritesOverlay?.collectionView.contentInset = inset
self.contentInsets = inset
}
}

Expand Down

0 comments on commit fd64707

Please sign in to comment.