mirror of
https://github.com/yattee/yattee.git
synced 2026-05-12 18:35:05 +00:00
Enforce minimum 2 grid columns on tvOS
This commit is contained in:
@@ -55,6 +55,15 @@ enum GridConstants {
|
||||
/// Maximum allowed columns (to prevent excessive density).
|
||||
static let maxAllowedColumns = 6
|
||||
|
||||
/// Minimum allowed columns. tvOS doesn't make sense with a single column.
|
||||
static let minAllowedColumns: Int = {
|
||||
#if os(tvOS)
|
||||
2
|
||||
#else
|
||||
1
|
||||
#endif
|
||||
}()
|
||||
|
||||
/// Threshold for compact card styling (columns >= this use compact mode).
|
||||
static let compactThreshold = 3
|
||||
}
|
||||
@@ -74,14 +83,14 @@ func maxGridColumns(
|
||||
// Formula: availableWidth = (columns * minCardWidth) + ((columns - 1) * spacing)
|
||||
// Solving for columns: columns = (availableWidth + spacing) / (minCardWidth + spacing)
|
||||
let maxColumns = Int((availableWidth + spacing) / (minCardWidth + spacing))
|
||||
return max(1, min(maxColumns, GridConstants.maxAllowedColumns))
|
||||
return max(GridConstants.minAllowedColumns, min(maxColumns, GridConstants.maxAllowedColumns))
|
||||
}
|
||||
|
||||
/// Creates grid columns for a LazyVGrid with the specified count.
|
||||
/// - Parameter count: Number of columns
|
||||
/// - Returns: Array of flexible GridItems with top alignment
|
||||
func makeGridColumns(count: Int) -> [GridItem] {
|
||||
Array(repeating: GridItem(.flexible(), spacing: GridConstants.spacing, alignment: .top), count: max(1, count))
|
||||
Array(repeating: GridItem(.flexible(), spacing: GridConstants.spacing, alignment: .top), count: max(GridConstants.minAllowedColumns, count))
|
||||
}
|
||||
|
||||
// MARK: - Grid Layout Configuration
|
||||
@@ -118,7 +127,7 @@ struct GridLayoutConfiguration {
|
||||
|
||||
/// Effective column count, clamped to valid range.
|
||||
var effectiveColumns: Int {
|
||||
min(max(1, gridColumns), max(1, maxColumns))
|
||||
min(max(GridConstants.minAllowedColumns, gridColumns), max(GridConstants.minAllowedColumns, maxColumns))
|
||||
}
|
||||
|
||||
/// Whether cards should use compact styling (3+ columns).
|
||||
|
||||
@@ -28,7 +28,7 @@ struct ViewOptionsSheet: View {
|
||||
|
||||
/// Effective columns clamped to valid range.
|
||||
private var effectiveColumns: Int {
|
||||
min(max(1, gridColumns), maxGridColumns)
|
||||
min(max(GridConstants.minAllowedColumns, gridColumns), max(GridConstants.minAllowedColumns, maxGridColumns))
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@@ -64,7 +64,7 @@ struct ViewOptionsSheet: View {
|
||||
|
||||
if layout == .grid {
|
||||
Picker("viewOptions.columns.header", selection: $gridColumns) {
|
||||
ForEach(1...maxGridColumns, id: \.self) { count in
|
||||
ForEach(GridConstants.minAllowedColumns...max(GridConstants.minAllowedColumns, maxGridColumns), id: \.self) { count in
|
||||
Text("\(count)").tag(count)
|
||||
}
|
||||
}
|
||||
@@ -123,7 +123,7 @@ struct ViewOptionsSheet: View {
|
||||
if layout == .grid {
|
||||
#if os(tvOS)
|
||||
Picker("viewOptions.columns.header", selection: $gridColumns) {
|
||||
ForEach(1...maxGridColumns, id: \.self) { count in
|
||||
ForEach(GridConstants.minAllowedColumns...max(GridConstants.minAllowedColumns, maxGridColumns), id: \.self) { count in
|
||||
Text("\(count)").tag(count)
|
||||
}
|
||||
}
|
||||
@@ -131,7 +131,7 @@ struct ViewOptionsSheet: View {
|
||||
Stepper(
|
||||
"viewOptions.columns \(effectiveColumns)",
|
||||
value: $gridColumns,
|
||||
in: 1...maxGridColumns
|
||||
in: GridConstants.minAllowedColumns...max(GridConstants.minAllowedColumns, maxGridColumns)
|
||||
)
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -142,16 +142,16 @@ struct ManageChannelsView: View {
|
||||
if layout == .grid {
|
||||
#if os(tvOS)
|
||||
Picker("viewOptions.columns.header", selection: $gridColumns) {
|
||||
ForEach(1...max(1, gridConfig.maxColumns), id: \.self) { count in
|
||||
ForEach(GridConstants.minAllowedColumns...max(GridConstants.minAllowedColumns, gridConfig.maxColumns), id: \.self) { count in
|
||||
Text("\(count)").tag(count)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
#else
|
||||
Stepper(
|
||||
"viewOptions.columns \(min(max(1, gridColumns), gridConfig.maxColumns))",
|
||||
"viewOptions.columns \(min(max(GridConstants.minAllowedColumns, gridColumns), gridConfig.maxColumns))",
|
||||
value: $gridColumns,
|
||||
in: 1...gridConfig.maxColumns
|
||||
in: GridConstants.minAllowedColumns...max(GridConstants.minAllowedColumns, gridConfig.maxColumns)
|
||||
)
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -359,16 +359,16 @@ struct SubscriptionsView: View {
|
||||
if layout == .grid {
|
||||
#if os(tvOS)
|
||||
Picker("viewOptions.columns.header", selection: $gridColumns) {
|
||||
ForEach(1...max(1, gridConfig.maxColumns), id: \.self) { count in
|
||||
ForEach(GridConstants.minAllowedColumns...max(GridConstants.minAllowedColumns, gridConfig.maxColumns), id: \.self) { count in
|
||||
Text("\(count)").tag(count)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
#else
|
||||
Stepper(
|
||||
"viewOptions.columns \(min(max(1, gridColumns), gridConfig.maxColumns))",
|
||||
"viewOptions.columns \(min(max(GridConstants.minAllowedColumns, gridColumns), gridConfig.maxColumns))",
|
||||
value: $gridColumns,
|
||||
in: 1...gridConfig.maxColumns
|
||||
in: GridConstants.minAllowedColumns...max(GridConstants.minAllowedColumns, gridConfig.maxColumns)
|
||||
)
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user