From ba0a2915db44e8bfdc79039b0a7b4646319941c6 Mon Sep 17 00:00:00 2001 From: Chris Brind Date: Fri, 29 Nov 2024 18:50:11 +0000 Subject: [PATCH] improve suggestion scrolling in landscape, favorites columns in the overlay and height calculation on ipad --- DuckDuckGo.xcodeproj/project.pbxproj | 4 --- DuckDuckGo/AutocompleteViewController.swift | 26 +++++++++++++++---- .../FavoritesHomeViewSectionRenderer.swift | 14 +++------- DuckDuckGo/FavoritesOverlay.swift | 13 ++++++++-- DuckDuckGo/MainViewController.swift | 3 ++- DuckDuckGo/SuggestionTray.storyboard | 10 +++---- DuckDuckGo/SuggestionTrayViewController.swift | 16 ++++++++---- 7 files changed, 53 insertions(+), 33 deletions(-) diff --git a/DuckDuckGo.xcodeproj/project.pbxproj b/DuckDuckGo.xcodeproj/project.pbxproj index a5f1b08056..7ecf13cb43 100644 --- a/DuckDuckGo.xcodeproj/project.pbxproj +++ b/DuckDuckGo.xcodeproj/project.pbxproj @@ -2026,7 +2026,6 @@ 983C52E32C2C050B007B5747 /* BookmarksStateRepair.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksStateRepair.swift; sourceTree = ""; }; 983C52E52C2C0ABA007B5747 /* BookmarkStateRepairTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkStateRepairTests.swift; sourceTree = ""; }; 983D71B02A286E810072E26D /* SyncDebugViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SyncDebugViewController.swift; sourceTree = ""; }; - 983D88D52CED006000E99B46 /* UnitTests copy-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "UnitTests copy-Info.plist"; path = "/Users/bartek/Develop/iOS/UnitTests copy-Info.plist"; sourceTree = ""; }; 983E1349251EABF200149BD9 /* fi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fi; path = fi.lproj/InfoPlist.strings; sourceTree = ""; }; 983E134A251EABF200149BD9 /* fi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fi; path = fi.lproj/InfoPlist.strings; sourceTree = ""; }; 983E134C251EABF200149BD9 /* fi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fi; path = fi.lproj/InfoPlist.strings; sourceTree = ""; }; @@ -2041,7 +2040,6 @@ 984147C424F026C800362052 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/HomeRow.storyboard; sourceTree = ""; }; 984147CA24F02E9E00362052 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/DaxOnboarding.storyboard; sourceTree = ""; }; 98424AA92CED4F430071C7DB /* WebViewUnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = WebViewUnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 98424AAA2CED4F430071C7DB /* UnitTests copy-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "UnitTests copy-Info.plist"; path = "/Users/bartek/Develop/iOS/UnitTests copy-Info.plist"; sourceTree = ""; }; 9846AA6622BD3BBF007DE48E /* InitHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InitHelpers.swift; sourceTree = ""; }; 9847BFFD27A2DDB400DB07AA /* ContentBlocking.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentBlocking.swift; sourceTree = ""; }; 9847BFFF27A2DDBB00DB07AA /* AppPrivacyConfigurationDataProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppPrivacyConfigurationDataProvider.swift; sourceTree = ""; }; @@ -4259,8 +4257,6 @@ 83ED3B8D1FA8E63700B47556 /* README.md */, 83ED3B8C1FA8E61D00B47556 /* ManualTestsScript.md */, 85A313962028E78A00327D00 /* release_notes.txt */, - 983D88D52CED006000E99B46 /* UnitTests copy-Info.plist */, - 98424AAA2CED4F430071C7DB /* UnitTests copy-Info.plist */, ); sourceTree = ""; }; diff --git a/DuckDuckGo/AutocompleteViewController.swift b/DuckDuckGo/AutocompleteViewController.swift index ba914b9418..16785a25e8 100644 --- a/DuckDuckGo/AutocompleteViewController.swift +++ b/DuckDuckGo/AutocompleteViewController.swift @@ -204,16 +204,15 @@ class AutocompleteViewController: UIHostingController { guard let lastResults else { return } let messageHeight = model.isMessageVisible ? 196 : 0 - let cellHeight = 44 - let sectionPadding = 10 + let sectionPadding = 12 let controllerPadding = 20 let height = - (lastResults.topHits.count * cellHeight) + + sectionHeight(lastResults.topHits) + (lastResults.topHits.isEmpty ? 0 : sectionPadding) + - (lastResults.duckduckgoSuggestions.count * cellHeight) + + sectionHeight(lastResults.duckduckgoSuggestions) + (lastResults.duckduckgoSuggestions.isEmpty ? 0 : sectionPadding) + - (lastResults.localSuggestions.count * cellHeight) + + sectionHeight(lastResults.localSuggestions) + (lastResults.localSuggestions.isEmpty ? 0 : sectionPadding) + messageHeight + controllerPadding @@ -222,6 +221,23 @@ class AutocompleteViewController: UIHostingController { .autocompleteDidChangeContentHeight(height: CGFloat(height)) } + func sectionHeight(_ suggestions: [Suggestion]) -> Int { + let standardCellHeight = 44 + let subtitledCellHeight = 58 + + var height = 0 + for suggestion in suggestions { + switch suggestion { + case .phrase, .website: + height += standardCellHeight + + default: + height += subtitledCellHeight + } + } + return height + } + } extension AutocompleteViewController: AutocompleteViewModelDelegate { diff --git a/DuckDuckGo/FavoritesHomeViewSectionRenderer.swift b/DuckDuckGo/FavoritesHomeViewSectionRenderer.swift index 0d1646f259..673e6c4c37 100644 --- a/DuckDuckGo/FavoritesHomeViewSectionRenderer.swift +++ b/DuckDuckGo/FavoritesHomeViewSectionRenderer.swift @@ -89,20 +89,12 @@ class FavoritesHomeViewSectionRenderer { } func sectionMargin(in collectionView: UICollectionView) -> CGFloat { - if controller is FavoritesOverlay { - return Constants.largeModeMargin - } - - let margin: CGFloat if isPad { - margin = (collectionView.frame.width - Constants.searchWidthPad) / 2 + return Constants.largeModeMargin } else { let defaultMargin = FavoritesHomeViewSectionRenderer.Constants.sideInsets - let landscapeMargin = (collectionView.frame.width - Constants.searchWidth + defaultMargin) / 2 - margin = isPortrait ? defaultMargin : landscapeMargin + return (collectionView.frame.width - Constants.searchWidth + defaultMargin) / 2 } - - return margin } // Visible margin is adjusted for offset inside Favorite Cells @@ -188,7 +180,7 @@ class FavoritesHomeViewSectionRenderer { referenceSizeForHeaderInSection section: Int) -> CGSize? { return CGSize(width: 1, height: headerHeight) } - + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize? { diff --git a/DuckDuckGo/FavoritesOverlay.swift b/DuckDuckGo/FavoritesOverlay.swift index a93f2cdd4f..50c0bcb582 100644 --- a/DuckDuckGo/FavoritesOverlay.swift +++ b/DuckDuckGo/FavoritesOverlay.swift @@ -66,14 +66,23 @@ class FavoritesOverlay: UIViewController { collectionView.backgroundColor = .clear view.addSubview(collectionView) - + renderer.install(into: self) registerForKeyboardNotifications() decorate() } - + + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + + if isPad { + collectionView.flashScrollIndicators() + } + + } + override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() diff --git a/DuckDuckGo/MainViewController.swift b/DuckDuckGo/MainViewController.swift index 29ed297fec..da488fbfb4 100644 --- a/DuckDuckGo/MainViewController.swift +++ b/DuckDuckGo/MainViewController.swift @@ -432,7 +432,8 @@ class MainViewController: UIViewController { bookmarksDatabase: self.bookmarksDatabase, historyManager: self.historyManager, tabsModel: self.tabManager.model, - featureFlagger: self.featureFlagger) + featureFlagger: self.featureFlagger, + appSettings: self.appSettings) }) else { assertionFailure() return diff --git a/DuckDuckGo/SuggestionTray.storyboard b/DuckDuckGo/SuggestionTray.storyboard index 25374b6488..26b251012e 100644 --- a/DuckDuckGo/SuggestionTray.storyboard +++ b/DuckDuckGo/SuggestionTray.storyboard @@ -1,9 +1,9 @@ - + - + @@ -18,11 +18,11 @@ - + - + @@ -38,7 +38,7 @@ - + diff --git a/DuckDuckGo/SuggestionTrayViewController.swift b/DuckDuckGo/SuggestionTrayViewController.swift index f71ee490f5..c04120dcf0 100644 --- a/DuckDuckGo/SuggestionTrayViewController.swift +++ b/DuckDuckGo/SuggestionTrayViewController.swift @@ -43,8 +43,6 @@ class SuggestionTrayViewController: UIViewController { autocompleteController != nil } - private let appSettings = AppUserDefaults() - private var autocompleteController: AutocompleteViewController? private var favoritesOverlay: FavoritesOverlay? private var willRemoveAutocomplete = false @@ -53,6 +51,7 @@ class SuggestionTrayViewController: UIViewController { private let historyManager: HistoryManaging private let tabsModel: TabsModel private let featureFlagger: FeatureFlagger + private let appSettings: AppSettings var selectedSuggestion: Suggestion? { autocompleteController?.selectedSuggestion @@ -82,12 +81,19 @@ class SuggestionTrayViewController: UIViewController { } } - required init?(coder: NSCoder, favoritesViewModel: FavoritesListInteracting, bookmarksDatabase: CoreDataDatabase, historyManager: HistoryManaging, tabsModel: TabsModel, featureFlagger: FeatureFlagger) { + required init?(coder: NSCoder, + favoritesViewModel: FavoritesListInteracting, + bookmarksDatabase: CoreDataDatabase, + historyManager: HistoryManaging, + tabsModel: TabsModel, + featureFlagger: FeatureFlagger, + appSettings: AppSettings) { self.favoritesModel = favoritesViewModel self.bookmarksDatabase = bookmarksDatabase self.historyManager = historyManager self.tabsModel = tabsModel self.featureFlagger = featureFlagger + self.appSettings = appSettings super.init(coder: coder) } @@ -168,7 +174,7 @@ class SuggestionTrayViewController: UIViewController { topConstraint.constant = 4 let isFirstPresentation = fullHeightConstraint.isActive - if isFirstPresentation { + if isFirstPresentation { variableHeightConstraint.constant = Constant.suggestionTrayInitialHeight } @@ -326,6 +332,6 @@ extension SuggestionTrayViewController { private extension SuggestionTrayViewController { enum Constant { - static let suggestionTrayInitialHeight = 312.0 // ie 52 * 6 + static let suggestionTrayInitialHeight = 380.0 // ie 52 * 6 } }