Skip to content

Commit

Permalink
nicer animation for bottom bar, some code tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
brindy committed Oct 10, 2023
1 parent bc39498 commit fd963cc
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 73 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo/BrowserChromeManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protocol BrowserChromeDelegate: AnyObject {
var toolbarHeight: CGFloat { get }
var barsMaxHeight: CGFloat { get }

var omniBar: OmniBar! { get }
var omniBar: OmniBar { get }
var tabBarContainer: UIView { get }
}

Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/BrowsingMenu/BrowsingMenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class BrowsingMenuViewController: UIViewController {

var searchBarRect: () -> CGRect

var isAddressBarBottom: Bool {
var isAddressBarAtBottom: Bool {
searchBarRect().minY > view.frame.midY
}

Expand Down Expand Up @@ -227,7 +227,7 @@ final class BrowsingMenuViewController: UIViewController {
topConstraint.constant = frame.minY + (isIPhoneLandscape ? -10 : 5)
// Move menu up in Landscape, as bottom toolbar shrinks

let barPositionOffset: CGFloat = isAddressBarBottom ? 52 : 0
let barPositionOffset: CGFloat = isAddressBarAtBottom ? 52 : 0
bottomConstraint.constant = windowBounds.maxY - frame.maxY - (isIPhoneLandscape ? 2 : 10) - barPositionOffset
rightConstraint.constant = isIPad ? 67 : 10

Expand Down
32 changes: 22 additions & 10 deletions DuckDuckGo/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ extension MainViewFactory {

class NavigationBarContainer: UIView { }
private func createNavigationBarContainer() {
coordinator.omniBar = OmniBar.loadFromXib()
coordinator.omniBar.translatesAutoresizingMaskIntoConstraints = false
coordinator.navigationBarContainer = NavigationBarContainer()
coordinator.navigationBarContainer.addSubview(coordinator.omniBar)
superview.addSubview(coordinator.navigationBarContainer)
}

Expand Down Expand Up @@ -182,15 +185,22 @@ extension MainViewFactory {
private func constrainNavigationBarContainer() {
let navigationBarContainer = coordinator.navigationBarContainer!
let toolbar = coordinator.toolbar!
let omniBar = coordinator.omniBar!

coordinator.constraints.navigationBarContainerTop = navigationBarContainer.constrainView(superview.safeAreaLayoutGuide, by: .top)
coordinator.constraints.navigationBarContainerBottom = navigationBarContainer.constrainView(toolbar, by: .bottom, to: .top)
coordinator.constraints.omniBarBottom = omniBar.constrainView(navigationBarContainer, by: .bottom, relatedBy: .greaterThanOrEqual)

NSLayoutConstraint.activate([
coordinator.constraints.navigationBarContainerTop,
navigationBarContainer.constrainView(superview, by: .centerX),
navigationBarContainer.constrainView(superview, by: .width),
coordinator.constraints.navigationBarContainerTop,
navigationBarContainer.constrainAttribute(.height, to: 52),
navigationBarContainer.constrainAttribute(.height, to: 52, relatedBy: .greaterThanOrEqual),
omniBar.constrainAttribute(.height, to: 52),
omniBar.constrainView(navigationBarContainer, by: .top),
omniBar.constrainView(navigationBarContainer, by: .leading),
omniBar.constrainView(navigationBarContainer, by: .trailing),
coordinator.constraints.omniBarBottom,
])
}

Expand Down Expand Up @@ -306,22 +316,23 @@ class MainViewCoordinator {

let superview: UIView

var logoContainer: UIView!
var contentContainer: UIView!
var lastToolbarButton: UIBarButtonItem!
var logo: UIImageView!
var logoContainer: UIView!
var logoText: UIImageView!
var toolbar: UIToolbar!
var suggestionTrayContainer: UIView!
var contentContainer: UIView!
var navigationBarContainer: UIView!
var notificationBarContainer: UIView!
var omniBar: OmniBar!
var progress: ProgressView!
var statusBackground: UIView!
var suggestionTrayContainer: UIView!
var tabBarContainer: UIView!
var navigationBarContainer: UIView!
var progress: ProgressView!
var toolbar: UIToolbar!
var toolbarBackButton: UIBarButtonItem!
var toolbarForwardButton: UIBarButtonItem!
var toolbarFireButton: UIBarButtonItem!
var toolbarForwardButton: UIBarButtonItem!
var toolbarTabSwitcherButton: UIBarButtonItem!
var lastToolbarButton: UIBarButtonItem!

let constraints = Constraints()

Expand Down Expand Up @@ -358,6 +369,7 @@ class MainViewCoordinator {
var notificationContainerTopToNavigationBar: NSLayoutConstraint!
var notificationContainerTopToStatusBackground: NSLayoutConstraint!
var notificationContainerHeight: NSLayoutConstraint!
var omniBarBottom: NSLayoutConstraint!
var progressBarTop: NSLayoutConstraint!
var progressBarBottom: NSLayoutConstraint!
var statusBackgroundToNavigationBarContainerBottom: NSLayoutConstraint!
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/MainViewController+CookiesManaged.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extension MainViewController {
topURL == tabManager.current?.url
else { return }

omniBar.showOrScheduleCookiesManagedNotification(isCosmetic: isCosmetic)
viewCoordinator.omniBar.showOrScheduleCookiesManagedNotification(isCosmetic: isCosmetic)
}

}
4 changes: 2 additions & 2 deletions DuckDuckGo/MainViewController+KeyCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extension MainViewController {
}

var arrowKeys = [UIKeyCommand]()
if omniBar.textField.isFirstResponder {
if viewCoordinator.omniBar.textField.isFirstResponder {
arrowKeys = [
UIKeyCommand(title: "", action: #selector(keyboardMoveSelectionUp), input: UIKeyCommand.inputUpArrow, modifierFlags: []),
UIKeyCommand(title: "", action: #selector(keyboardMoveSelectionDown), input: UIKeyCommand.inputDownArrow, modifierFlags: [])
Expand Down Expand Up @@ -140,7 +140,7 @@ extension MainViewController {
controller.launchNewSearch()
} else {
showBars()
omniBar.becomeFirstResponder()
viewCoordinator.omniBar.becomeFirstResponder()
}
}

Expand Down
Loading

0 comments on commit fd963cc

Please sign in to comment.