From 45d96ecac82d5f72ca13a9188a69f352a2cf74ec Mon Sep 17 00:00:00 2001 From: CHARLES BOND Date: Sun, 18 Aug 2024 14:57:23 +0900 Subject: [PATCH] Rewrote to move clear outside TimetableGridCard --- .../TimetableFeature/TimetableGridCard.swift | 87 +++++++++---------- .../TimetableFeature/TimetableListView.swift | 19 ++-- 2 files changed, 51 insertions(+), 55 deletions(-) diff --git a/app-ios/Sources/TimetableFeature/TimetableGridCard.swift b/app-ios/Sources/TimetableFeature/TimetableGridCard.swift index 79435c618..41b10afff 100644 --- a/app-ios/Sources/TimetableFeature/TimetableGridCard.swift +++ b/app-ios/Sources/TimetableFeature/TimetableGridCard.swift @@ -4,11 +4,11 @@ import Theme import class shared.TimetableItem public struct TimetableGridCard: View { - let timetableItem: TimetableItem? + let timetableItem: TimetableItem let onTap: (TimetableItem) -> Void public init( - timetableItem: TimetableItem?, + timetableItem: TimetableItem, onTap: @escaping (TimetableItem) -> Void ) { self.timetableItem = timetableItem @@ -16,60 +16,51 @@ public struct TimetableGridCard: View { } public var body: some View { - if let timetableItem { - Button { - onTap(timetableItem) - } label: { - VStack(alignment: .leading, spacing: 8) { - HStack(spacing: 4) { - timetableItem.room.type.shape - .foregroundStyle(timetableItem.room.roomTheme.primaryColor) - Text("\(timetableItem.startsTimeString) - \(timetableItem.endsTimeString)") - .textStyle(.labelMedium) - .foregroundStyle(timetableItem.room.roomTheme.primaryColor) - Spacer() - } - - Text(timetableItem.title.currentLangTitle) - .textStyle(.titleMedium) + Button { + onTap(timetableItem) + } label: { + VStack(alignment: .leading, spacing: 8) { + HStack(spacing: 4) { + timetableItem.room.type.shape + .foregroundStyle(timetableItem.room.roomTheme.primaryColor) + Text("\(timetableItem.startsTimeString) - \(timetableItem.endsTimeString)") + .textStyle(.labelMedium) .foregroundStyle(timetableItem.room.roomTheme.primaryColor) - .multilineTextAlignment(.leading) - Spacer() - - ForEach(timetableItem.speakers, id: \.id) { speaker in - HStack(spacing: 8) { - Group { - AsyncImage(url: URL(string: speaker.iconUrl)) { - $0.resizable() - } placeholder: { - Color.gray - } + } + + Text(timetableItem.title.currentLangTitle) + .textStyle(.titleMedium) + .foregroundStyle(timetableItem.room.roomTheme.primaryColor) + .multilineTextAlignment(.leading) + + Spacer() + + ForEach(timetableItem.speakers, id: \.id) { speaker in + HStack(spacing: 8) { + Group { + AsyncImage(url: URL(string: speaker.iconUrl)) { + $0.resizable() + } placeholder: { + Color.gray } - .frame(width: 32, height: 32) - .clipShape(Circle()) - - Text(speaker.name) - .textStyle(.titleSmall) - .foregroundStyle(AssetColors.Surface.onSurfaceVariant.swiftUIColor) - .lineLimit(1) } + .frame(width: 32, height: 32) + .clipShape(Circle()) + + Text(speaker.name) + .textStyle(.titleSmall) + .foregroundStyle(AssetColors.Surface.onSurfaceVariant.swiftUIColor) + .lineLimit(1) } } - .frame(maxWidth: .infinity) - .padding(12) - .frame(width: 192, height: 153) - .background(timetableItem.room.roomTheme.containerColor, in: RoundedRectangle(cornerRadius: 4)) - .overlay(RoundedRectangle(cornerRadius: 4).stroke(timetableItem.room.roomTheme.primaryColor, lineWidth: 1)) } - } else { - Color.clear - .frame(maxWidth: .infinity) - .padding(12) - .frame(width: 192, height: 153) - .background(Color.clear, in: RoundedRectangle(cornerRadius: 4)) + .frame(maxWidth: .infinity) + .padding(12) + .frame(width: 192, height: 153) + .background(timetableItem.room.roomTheme.containerColor, in: RoundedRectangle(cornerRadius: 4)) + .overlay(RoundedRectangle(cornerRadius: 4).stroke(timetableItem.room.roomTheme.primaryColor, lineWidth: 1)) } - } } diff --git a/app-ios/Sources/TimetableFeature/TimetableListView.swift b/app-ios/Sources/TimetableFeature/TimetableListView.swift index 90a37ec8c..fdc803827 100644 --- a/app-ios/Sources/TimetableFeature/TimetableListView.swift +++ b/app-ios/Sources/TimetableFeature/TimetableListView.swift @@ -137,9 +137,16 @@ struct TimetableGridView: View { ForEach(rooms, id: \.self) { room in - timeBlock.getCellForRoom(room: room, onTap: { item in - store.send(.view(.timetableItemTapped(item))) - }) + if let cell = timeBlock.getCellForRoom(room: room, onTap: { item in + store.send(.view(.timetableItemTapped(item)))}) { + cell + } else { + Color.clear + .frame(maxWidth: .infinity) + .padding(12) + .frame(width: 192, height: 153) + .background(Color.clear, in: RoundedRectangle(cornerRadius: 4)) + } } } } @@ -248,15 +255,13 @@ extension RoomType { } extension TimetableTimeGroupItems { - func getCellForRoom(room: RoomType, onTap: @escaping (TimetableItemWithFavorite) -> Void) -> TimetableGridCard { + func getCellForRoom(room: RoomType, onTap: @escaping (TimetableItemWithFavorite) -> Void) -> TimetableGridCard? { return if let cell = getItem(for: room) { TimetableGridCard(timetableItem: cell.timetableItem) { timetableItem in onTap(cell) } } else { - TimetableGridCard(timetableItem: nil) { _ in - // Does nothing / Space holder card - } + nil } } }