Skip to content

Commit

Permalink
Rewrote to move clear outside TimetableGridCard
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-b-stb committed Aug 18, 2024
1 parent 16262aa commit 45d96ec
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 55 deletions.
87 changes: 39 additions & 48 deletions app-ios/Sources/TimetableFeature/TimetableGridCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,63 @@ 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
self.onTap = onTap
}

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))
}

}
}

Expand Down
19 changes: 12 additions & 7 deletions app-ios/Sources/TimetableFeature/TimetableListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
}
Expand Down Expand Up @@ -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
}
}
}
Expand Down

0 comments on commit 45d96ec

Please sign in to comment.