Skip to content

Commit

Permalink
set cell colours and fix top panel thing
Browse files Browse the repository at this point in the history
  • Loading branch information
brindy committed Oct 11, 2023
1 parent f8ed300 commit 8e0b56b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
3 changes: 1 addition & 2 deletions DuckDuckGo/AutocompleteViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ extension AutocompleteViewController: UITableViewDataSource {
cell.updateFor(query: query, suggestion: suggestions[indexPath.row], with: currentTheme, isAddressBarAtBottom: isAddressBarAtBottom)
cell.plusButton.tag = indexPath.row

let baseBackgroundColor = isAddressBarAtBottom ? UIColor(designSystemColor: .background) : UIColor(designSystemColor: .panel)
let backgroundColor = indexPath.row == selectedItem ? currentTheme.tableCellSelectedColor : baseBackgroundColor
let backgroundColor = indexPath.row == selectedItem ? currentTheme.tableCellSelectedColor : UIColor(designSystemColor: .background)

cell.backgroundColor = backgroundColor
cell.tintColor = currentTheme.autocompleteCellAccessoryColor
Expand Down
50 changes: 27 additions & 23 deletions DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ class MainViewController: UIViewController {
}

var isAddressBarAtBottom: Bool {
searchBarRect.minY > view.frame.midY
if searchBarRect == .zero {
return appSettings.currentAddressBarPosition == .bottom
}

return searchBarRect.minY > view.frame.midY
}

var keyModifierFlags: UIKeyModifierFlags?
Expand Down Expand Up @@ -222,7 +226,8 @@ class MainViewController: UIViewController {
registerForOrientationChangeNotification()

tabManager.cleanupTabsFaviconCache()
refreshViewsBasedOnAddressBarPosition()

refreshViewsBasedOnAddressBarPosition(appSettings.currentAddressBarPosition)
}

override func viewDidAppear(_ animated: Bool) {
Expand Down Expand Up @@ -252,12 +257,7 @@ class MainViewController: UIViewController {
}

@objc func orientationDidChange() {
if UIDevice.current.orientation.isLandscape {
viewCoordinator.moveAddressBarToPosition(.top)
} else {
viewCoordinator.moveAddressBarToPosition(appSettings.currentAddressBarPosition)
}
refreshViewsBasedOnAddressBarPosition()
onAddressBarPositionChanged()
}

func loadSuggestionTray() {
Expand Down Expand Up @@ -331,13 +331,17 @@ class MainViewController: UIViewController {
}

@objc func onAddressBarPositionChanged() {
viewCoordinator.moveAddressBarToPosition(appSettings.currentAddressBarPosition)
decorate(with: ThemeManager.shared.currentTheme)
refreshViewsBasedOnAddressBarPosition()
if UIDevice.current.orientation.isLandscape {
viewCoordinator.moveAddressBarToPosition(.top)
refreshViewsBasedOnAddressBarPosition(.top)
} else {
viewCoordinator.moveAddressBarToPosition(appSettings.currentAddressBarPosition)
refreshViewsBasedOnAddressBarPosition(appSettings.currentAddressBarPosition)
}
}

func refreshViewsBasedOnAddressBarPosition() {
switch appSettings.currentAddressBarPosition {
func refreshViewsBasedOnAddressBarPosition(_ position: AddressBarPosition) {
switch position {
case .top:
viewCoordinator.omniBar.moveSeparatorToBottom()
viewCoordinator.showToolbarSeparator()
Expand All @@ -346,6 +350,12 @@ class MainViewController: UIViewController {
viewCoordinator.omniBar.moveSeparatorToTop()
viewCoordinator.hideToolbarSeparator()
}

DispatchQueue.main.async {
// Do this in the next cycle so that the position of the bar is correctly reported
let theme = ThemeManager.shared.currentTheme
self.decorate(with: theme)
}
}

@objc func onShowFullSiteAddressChanged() {
Expand Down Expand Up @@ -396,15 +406,7 @@ class MainViewController: UIViewController {
let frame = self.findInPageView.frame
UIView.animate(withDuration: duration, delay: 0, options: animationCurve, animations: {
self.findInPageView.frame = CGRect(x: 0, y: y - frame.height, width: frame.width, height: frame.height)

// Before iOS 17 this causes the omnibar to animate its contents.
if #available(iOS 17, *) {
self.viewCoordinator.superview.layoutIfNeeded()
}
}, completion: nil)

// Don't wait for the animation cycle to layout the omnibar's children - only seems to work on iOS 17
self.viewCoordinator.omniBar.layoutSubviews()
}

private func initTabButton() {
Expand Down Expand Up @@ -901,7 +903,7 @@ class MainViewController: UIViewController {
if !DaxDialogs.shared.shouldShowFireButtonPulse {
ViewHighlighter.hideAll()
}
if type.hideOmnibarSeparator() && appSettings.currentAddressBarPosition == .top {
if type.hideOmnibarSeparator() && !isAddressBarAtBottom {
viewCoordinator.omniBar.hideSeparator()
}
}
Expand Down Expand Up @@ -1923,6 +1925,8 @@ extension MainViewController: AutoClearWorker {
extension MainViewController: Themable {

func decorate(with theme: Theme) {
print("***", #function)

setNeedsStatusBarAppearanceUpdate()

// Does not appear to get updated when setting changes.
Expand Down Expand Up @@ -1958,7 +1962,7 @@ extension MainViewController: Themable {

viewCoordinator.logoText.tintColor = theme.ddgTextTintColor

if appSettings.currentAddressBarPosition == .bottom {
if isAddressBarAtBottom {
viewCoordinator.statusBackground.backgroundColor = theme.backgroundColor
}
}
Expand Down

0 comments on commit 8e0b56b

Please sign in to comment.