Skip to content

Commit

Permalink
Fix margins on small screens
Browse files Browse the repository at this point in the history
  • Loading branch information
dus7 committed Nov 12, 2024
1 parent 91825dc commit 692f9f7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
15 changes: 13 additions & 2 deletions DuckDuckGo/NewTabPageGridView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,21 @@ enum NewTabPageGrid {
let usesWideLayout = isLandscape || sizeClass == .regular
return usesWideLayout ? ColumnCount.regular : ColumnCount.compact
} else {
return UIDevice.current.userInterfaceIdiom == .pad ? ColumnCount.iPadStaticLayout : ColumnCount.compact
return staticGridColumnsCount(for: sizeClass)
}
}

static func staticGridWidth(for sizeClass: UserInterfaceSizeClass?) -> CGFloat {
let columnsCount = CGFloat(staticGridColumnsCount(for: sizeClass))
return columnsCount * Item.edgeSize + (columnsCount - 1) * Item.staticSpacing
}

private static func staticGridColumnsCount(for sizeClass: UserInterfaceSizeClass?) -> Int {
let isPad = UIDevice.current.userInterfaceIdiom == .pad

return isPad && sizeClass == .regular ? ColumnCount.staticWideLayout : ColumnCount.compact
}

enum Item {
static let edgeSize = 64.0
}
Expand All @@ -104,7 +115,7 @@ private extension NewTabPageGrid {
enum ColumnCount {
static let compact = 4
static let regular = 6
static let iPadStaticLayout = 5
static let staticWideLayout = 5
}
}

Expand Down
13 changes: 9 additions & 4 deletions DuckDuckGo/SimpleNewTabPageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private extension SimpleNewTabPageView {

favoritesSectionView(proxy: proxy)
}
.padding(Metrics.largePadding)
.padding(sectionsViewPadding(in: proxy))
}
.withScrollKeyboardDismiss()
}
Expand All @@ -99,7 +99,7 @@ private extension SimpleNewTabPageView {
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
}
.padding(Metrics.largePadding)
.padding(Metrics.regularPadding)
}

private var messagesSectionView: some View {
Expand All @@ -115,6 +115,11 @@ private extension SimpleNewTabPageView {
isAddingFavorite: .constant(false),
geometry: proxy)
}

private func sectionsViewPadding(in geometry: GeometryProxy) -> CGFloat {
let requiredWidth = NewTabPageGrid.staticGridWidth(for: horizontalSizeClass) + Metrics.regularPadding
return geometry.frame(in: .local).width >= requiredWidth ? Metrics.regularPadding : Metrics.smallPadding
}
}

private extension View {
Expand All @@ -130,8 +135,8 @@ private extension View {

private struct Metrics {

static let regularPadding = 16.0
static let largePadding = 24.0
static let smallPadding = 12.0
static let regularPadding = 24.0
static let sectionSpacing = 32.0
static let nonGridSectionTopPadding = -8.0

Expand Down

0 comments on commit 692f9f7

Please sign in to comment.