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 87fb9c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
11 changes: 10 additions & 1 deletion DuckDuckGo/NewTabPageGridView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,19 @@ 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
}
}

static var staticGridWidth: CGFloat {
let columnsCount = CGFloat(staticGridColumnsCount)
return columnsCount * Item.edgeSize + (columnsCount - 1) * Item.staticSpacing
}

private static var staticGridColumnsCount: Int {
UIDevice.current.userInterfaceIdiom == .pad ? ColumnCount.iPadStaticLayout : ColumnCount.compact
}

enum Item {
static let edgeSize = 64.0
}
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 + 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 87fb9c8

Please sign in to comment.