Widget: family-aware row cap — large/extraLarge show 5 stations, medium 3

The 3-row cap was hardcoded for the medium widget height; large widgets
have ~2x the height and fit 5 compact rows. Timeline now carries up to
8 stations (was 4) so the large list never starves. Distance picker
still controls which stations are in range; the visible row count now
depends on widget size, not the distance setting.
This commit is contained in:
FuelBoard Contributor
2026-08-12 16:35:42 +01:00
parent fccd0c07ef
commit d37aab04f1
+13 -3
View File
@@ -64,7 +64,7 @@ struct FuelPriceTimelineProvider: AppIntentTimelineProvider {
.filter { $0.prices[.e10] != nil }
.sorted { $0.prices[.e10]! < $1.prices[.e10]! }
return FuelPriceEntry(
date: Date(), stations: Array(sample.prefix(4)),
date: Date(), stations: Array(sample.prefix(8)),
fuel: .e10, sort: .cheapest, isFavourites: false,
location: nil, locationSource: "none", unit: unit
)
@@ -189,7 +189,7 @@ struct FuelPriceTimelineProvider: AppIntentTimelineProvider {
}
return FuelPriceEntry(
date: Date(), stations: Array(ordered.prefix(4)),
date: Date(), stations: Array(ordered.prefix(8)),
fuel: fuel, sort: sort, isFavourites: isFavourites,
location: location, locationSource: source,
unit: unit
@@ -287,6 +287,16 @@ struct FuelPriceWidgetView: View {
.widgetURL(station.widgetDirectionsURL)
}
/// How many station rows each family can fit: medium widgets are short
/// (158pt) so 3 rows is the safe cap; large/extraLarge have ~2× the height
/// and fit 5 compact rows. Small widgets use singleStation instead.
private var maxRows: Int {
switch family {
case .systemMedium: return 3
default: return 5
}
}
private var stationList: some View {
let cheapest = entry.stations.compactMap { $0.prices[entry.fuel] }.min()
return VStack(alignment: .leading, spacing: 6) {
@@ -302,7 +312,7 @@ struct FuelPriceWidgetView: View {
.font(.caption2)
.foregroundStyle(.secondary)
}
ForEach(entry.stations.prefix(3)) { station in
ForEach(entry.stations.prefix(maxRows)) { station in
Link(destination: station.widgetDirectionsURL ?? URL(string: "maps://")!) {
HStack(spacing: 8) {
Text(station.name)