From ce5c8b73c8904a2dc49246d46cc537cbf2a95c28 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 29 Apr 2024 17:15:45 +0200 Subject: [PATCH] Improve date view --- .../Views/Tournament/Shared/DateBoxView.swift | 64 ++++++++++++++----- .../Shared/TournamentCellView.swift | 21 +++++- 2 files changed, 66 insertions(+), 19 deletions(-) diff --git a/PadelClub/Views/Tournament/Shared/DateBoxView.swift b/PadelClub/Views/Tournament/Shared/DateBoxView.swift index 470570b..62a7afc 100644 --- a/PadelClub/Views/Tournament/Shared/DateBoxView.swift +++ b/PadelClub/Views/Tournament/Shared/DateBoxView.swift @@ -7,29 +7,59 @@ import SwiftUI -struct DateBoxView: View { +struct DateVerticalView: View { + let date: Date + var body: some View { + VStack(alignment: .trailing, spacing: 0.0) { + DateView(date: self.date) + MonthYearView(date: self.date) + } + } +} + +struct DateView: View { let date: Date - var displayStyle: DisplayStyle = .wide - var body: some View { VStack(alignment: .center, spacing: 0.0) { - Text(date.formatted(.dateTime.weekday(.abbreviated)).uppercased()) - HStack(alignment: .bottom) { - Text(date.formatted(.dateTime.day(.twoDigits))) - .font(displayStyle == .wide ? .title : .title3) - .monospacedDigit() - .padding(-2) - } - if displayStyle == .wide { - Text(date.formatted(.dateTime.month(.abbreviated)).uppercased()) - Text(date.formatted(.dateTime.year())) - } + Text(self.date.formatted(.dateTime.weekday(.abbreviated)).uppercased()) + Text(self.date.formatted(.dateTime.day(.twoDigits))) + .font(.title3).fontWeight(.semibold) + .monospacedDigit() } - .font(.footnote) - .fontWeight(.semibold) } } +struct MonthYearView: View { + let date: Date + var body: some View { + Text(date.formatted(.dateTime.month(.abbreviated)).uppercased()) + Text(date.formatted(.dateTime.year())) + } +} + +//struct DateBoxView: View { +// let date: Date +// var displayStyle: DisplayStyle = .wide +// +// var body: some View { +// VStack(alignment: .center, spacing: 0.0) { +// Text(date.formatted(.dateTime.weekday(.abbreviated)).uppercased()) +// HStack(alignment: .bottom) { +// Text(date.formatted(.dateTime.day(.twoDigits))) +// .font(displayStyle == .wide ? .title : .title3) +// .monospacedDigit() +// .padding(-2) +// } +// if displayStyle == .wide { +// Text(date.formatted(.dateTime.month(.abbreviated)).uppercased()) +// Text(date.formatted(.dateTime.year())) +// } +// } +// .font(.footnote) +//// .fontWeight(.semibold) +// } +//} + #Preview { - DateBoxView(date: Date()) + DateVerticalView(date: Date()) } diff --git a/PadelClub/Views/Tournament/Shared/TournamentCellView.swift b/PadelClub/Views/Tournament/Shared/TournamentCellView.swift index 4b78e49..01135e8 100644 --- a/PadelClub/Views/Tournament/Shared/TournamentCellView.swift +++ b/PadelClub/Views/Tournament/Shared/TournamentCellView.swift @@ -26,9 +26,26 @@ struct TournamentCellView: View { } } + fileprivate func _spacing() -> CGFloat { + self.displayStyle == .short ? 8.0 : 16.0 + } + private func _buildView(_ build: any TournamentBuildHolder, existingTournament: Tournament?) -> some View { - HStack(spacing: 16.0) { - DateBoxView(date: tournament.startDate, displayStyle: displayStyle == .wide ? .short : .wide) + HStack(spacing: self._spacing()) { + switch displayStyle { + case .short: + DateVerticalView(date: tournament.startDate) + case .wide: + VStack(alignment: .center, spacing: -2.0) { + Text(tournament.startDate.formatted(.dateTime.weekday(.abbreviated)).uppercased()) + .font(.system(size: 14.0)).fontWeight(.medium) + Text(tournament.startDate.formatted(.dateTime.day(.twoDigits))) + .font(.title).fontWeight(.semibold) +// .monospacedDigit() + } + } +// DateBoxView(date: tournament.startDate, displayStyle: displayStyle == .wide ? .short : .wide) +// .fontWeight(displayStyle == .wide ? .semibold : .regular) // Rectangle() // .fill(Color(white: 0.8)) // .frame(width: 2)