Small spreadsheet UI updates

This commit is contained in:
2026-04-05 00:27:29 -05:00
parent 46e61bae00
commit ca8bf48810

View File

@@ -44,25 +44,41 @@ struct SpreadsheetView: View {
},
]
private static let headerHeight: CGFloat = 48
private static let topBarHeight: CGFloat = 52
private static let headerHeight: CGFloat = 44
var body: some View {
VStack(spacing: 0) {
// Top bar
HStack(spacing: 4) {
Button {
restorePortrait()
onDismiss()
} label: {
Image(systemName: "xmark.circle.fill")
.font(.title2)
.foregroundStyle(.secondary)
ZStack(alignment: .top) {
Color(.systemBackground).ignoresSafeArea()
// Full-screen table padded down so it starts below the floating bar
GeometryReader { proxy in
ScrollView(.horizontal, showsIndicators: true) {
VStack(alignment: .leading, spacing: 0) {
columnHeaderRow
Divider()
ScrollView(.vertical, showsIndicators: true) {
LazyVStack(spacing: 0) {
ForEach(Array(chemicals.enumerated()), id: \.element.id) { idx, chemical in
dataRow(chemical: chemical, index: idx)
Divider()
}
}
}
.frame(height: max(0, proxy.size.height - Self.topBarHeight - Self.headerHeight - 1))
}
}
.padding(.top, Self.topBarHeight)
}
// Floating Liquid Glass top bar
HStack(spacing: 0) {
closeButton
.padding(.leading, 12)
Text("Inventory Spreadsheet")
.font(.headline)
.padding(.leading, 4)
.padding(.leading, 8)
Spacer()
@@ -71,16 +87,22 @@ struct SpreadsheetView: View {
.foregroundStyle(.secondary)
.padding(.trailing, 16)
}
.frame(height: 50)
.background(Color(.systemBackground))
.frame(height: Self.topBarHeight)
.background(.regularMaterial)
}
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) {
setLandscape()
}
}
.onDisappear {
restorePortrait()
}
}
Divider()
// MARK: - Subviews
// Table
GeometryReader { proxy in
ScrollView(.horizontal, showsIndicators: true) {
VStack(alignment: .leading, spacing: 0) {
// Sticky header row
private var columnHeaderRow: some View {
HStack(spacing: 0) {
ForEach(Array(Self.columnDefs.enumerated()), id: \.offset) { i, col in
Text(col.label)
@@ -88,67 +110,71 @@ struct SpreadsheetView: View {
.foregroundStyle(.white)
.lineLimit(2)
.multilineTextAlignment(.center)
.frame(width: col.width, height: Self.headerHeight)
// 📍 Move padding INSIDE
.padding(.horizontal, 4)
// 📍 Frame goes OUTSIDE to lock the total width safely
.frame(width: col.width, height: Self.headerHeight)
if i < Self.columnDefs.count - 1 {
Rectangle()
.fill(Color.white.opacity(0.35))
.fill(Color.white.opacity(0.3))
.frame(width: 1, height: Self.headerHeight)
}
}
}
.background(Color.accentColor)
}
Divider()
// Scrollable data rows
ScrollView(.vertical, showsIndicators: true) {
LazyVStack(spacing: 0) {
ForEach(Array(chemicals.enumerated()), id: \.element.id) { idx, chemical in
private func dataRow(chemical: Chemical, index: Int) -> some View {
HStack(spacing: 0) {
ForEach(Array(Self.columnDefs.enumerated()), id: \.offset) { i, col in
Text(col.value(chemical))
.font(.caption)
.lineLimit(1)
.frame(width: col.width, alignment: .leading)
// 📍 Move padding INSIDE
.padding(.vertical, 7)
.padding(.horizontal, 6)
.background(idx % 2 == 0
// 📍 Frame goes OUTSIDE to lock the total width safely
.frame(width: col.width, alignment: .leading)
.background(index % 2 == 0
? Color(.systemBackground)
: Color(.systemGray6))
: Color(.systemGroupedBackground))
if i < Self.columnDefs.count - 1 {
Rectangle()
.fill(Color(.separator))
.frame(width: 0.5)
.frame(height: 30)
// 📍 Changed to 1px to perfectly match the header divider!
.frame(width: 1, height: 30)
}
}
}
Divider()
}
}
}
// Subtract header height and the 1-pt divider
.frame(height: proxy.size.height - Self.headerHeight - 1)
}
}
}
}
.onAppear {
// Slight delay so the full-screen cover animation finishes before rotating
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) {
setLandscape()
}
}
.onDisappear {
// Safety net in case something else dismisses this view
restorePortrait()
}
}
// MARK: - Orientation helpers
/// Close button: Liquid Glass on iOS 26+, plain icon on older releases.
@ViewBuilder
private var closeButton: some View {
if #available(iOS 26.0, *) {
Button {
restorePortrait()
onDismiss()
} label: {
Image(systemName: "xmark")
.font(.system(size: 14, weight: .bold))
}
.buttonStyle(.glass)
} else {
Button {
restorePortrait()
onDismiss()
} label: {
Image(systemName: "xmark.circle.fill")
.font(.title2)
.foregroundStyle(.secondary)
}
}
}
// MARK: - Orientation
private func setLandscape() {
AppDelegate.orientationLock = .landscape