Skip to content

Commit

Permalink
improve suggestion scrolling in landscape, favorites columns in the o…
Browse files Browse the repository at this point in the history
…verlay and height calculation on ipad
  • Loading branch information
brindy committed Nov 29, 2024
1 parent 68a69a9 commit ba0a291
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 33 deletions.
4 changes: 0 additions & 4 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2026,7 +2026,6 @@
983C52E32C2C050B007B5747 /* BookmarksStateRepair.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksStateRepair.swift; sourceTree = "<group>"; };
983C52E52C2C0ABA007B5747 /* BookmarkStateRepairTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkStateRepairTests.swift; sourceTree = "<group>"; };
983D71B02A286E810072E26D /* SyncDebugViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SyncDebugViewController.swift; sourceTree = "<group>"; };
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 = "<absolute>"; };
983E1349251EABF200149BD9 /* fi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fi; path = fi.lproj/InfoPlist.strings; sourceTree = "<group>"; };
983E134A251EABF200149BD9 /* fi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fi; path = fi.lproj/InfoPlist.strings; sourceTree = "<group>"; };
983E134C251EABF200149BD9 /* fi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fi; path = fi.lproj/InfoPlist.strings; sourceTree = "<group>"; };
Expand All @@ -2041,7 +2040,6 @@
984147C424F026C800362052 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/HomeRow.storyboard; sourceTree = "<group>"; };
984147CA24F02E9E00362052 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/DaxOnboarding.storyboard; sourceTree = "<group>"; };
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 = "<absolute>"; };
9846AA6622BD3BBF007DE48E /* InitHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InitHelpers.swift; sourceTree = "<group>"; };
9847BFFD27A2DDB400DB07AA /* ContentBlocking.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentBlocking.swift; sourceTree = "<group>"; };
9847BFFF27A2DDBB00DB07AA /* AppPrivacyConfigurationDataProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppPrivacyConfigurationDataProvider.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 = "<group>";
};
Expand Down
26 changes: 21 additions & 5 deletions DuckDuckGo/AutocompleteViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,15 @@ class AutocompleteViewController: UIHostingController<AutocompleteView> {
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
Expand All @@ -222,6 +221,23 @@ class AutocompleteViewController: UIHostingController<AutocompleteView> {
.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 {
Expand Down
14 changes: 3 additions & 11 deletions DuckDuckGo/FavoritesHomeViewSectionRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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? {
Expand Down
13 changes: 11 additions & 2 deletions DuckDuckGo/FavoritesOverlay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions DuckDuckGo/SuggestionTray.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="GVY-7c-Fnx">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="23504" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="GVY-7c-Fnx">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22684"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="23506"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand All @@ -18,11 +18,11 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="vmf-xs-TwY" userLabel="Background View">
<rect key="frame" x="0.0" y="0.0" width="393" height="818"/>
<rect key="frame" x="0.0" y="0.0" width="393" height="768"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="64L-Y0-7ie">
<rect key="frame" x="0.0" y="0.0" width="393" height="818"/>
<rect key="frame" x="0.0" y="0.0" width="393" height="768"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="height" priority="999" constant="908" id="1GN-2u-5xs"/>
Expand All @@ -38,7 +38,7 @@
<constraint firstItem="vmf-xs-TwY" firstAttribute="centerY" secondItem="64L-Y0-7ie" secondAttribute="centerY" id="Ggk-fs-YmX"/>
<constraint firstItem="64L-Y0-7ie" firstAttribute="width" secondItem="j0c-gb-rpc" secondAttribute="width" id="OLF-Z3-QnI"/>
<constraint firstItem="vmf-xs-TwY" firstAttribute="width" secondItem="64L-Y0-7ie" secondAttribute="width" id="Xqu-w2-wf9"/>
<constraint firstItem="ki7-21-ggp" firstAttribute="bottom" secondItem="64L-Y0-7ie" secondAttribute="bottom" id="ac9-7J-RDs"/>
<constraint firstItem="ki7-21-ggp" firstAttribute="bottom" secondItem="64L-Y0-7ie" secondAttribute="bottom" constant="50" id="ac9-7J-RDs"/>
<constraint firstItem="vmf-xs-TwY" firstAttribute="height" secondItem="64L-Y0-7ie" secondAttribute="height" id="ebY-43-deK"/>
<constraint firstItem="ki7-21-ggp" firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="64L-Y0-7ie" secondAttribute="bottom" id="mSE-jr-Q7R"/>
<constraint firstItem="64L-Y0-7ie" firstAttribute="centerX" secondItem="j0c-gb-rpc" secondAttribute="centerX" id="rtq-3b-s1Z"/>
Expand Down
16 changes: 11 additions & 5 deletions DuckDuckGo/SuggestionTrayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -168,7 +174,7 @@ class SuggestionTrayViewController: UIViewController {
topConstraint.constant = 4

let isFirstPresentation = fullHeightConstraint.isActive
if isFirstPresentation {
if isFirstPresentation {

Check failure on line 177 in DuckDuckGo/SuggestionTrayViewController.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Lines should not have trailing whitespace (trailing_whitespace)
variableHeightConstraint.constant = Constant.suggestionTrayInitialHeight
}

Expand Down Expand Up @@ -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
}
}

0 comments on commit ba0a291

Please sign in to comment.