Skip to content

Commit

Permalink
Merge pull request #25 from edx/2U/feat/primary-horizontal
Browse files Browse the repository at this point in the history
feat: Landscape mode Improvement
  • Loading branch information
rnr committed Oct 1, 2024
1 parent 9733568 commit 6267364
Showing 1 changed file with 52 additions and 8 deletions.
60 changes: 52 additions & 8 deletions Dashboard/Dashboard/Presentation/Elements/PrimaryCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public struct PrimaryCardView: View {
private var assignmentAction: (String?) -> Void
private var openCourseAction: () -> Void
private var resumeAction: () -> Void
private var upgradeAction: () -> Void
private var isUpgradeable: Bool
@Environment(\.isHorizontal) var isHorizontal

public init(
courseName: String,
Expand Down Expand Up @@ -64,22 +67,65 @@ public struct PrimaryCardView: View {

public var body: some View {
ZStack {
if isHorizontal {
horizontalLayout
} else {
verticalLayout
}
}
.background(Theme.Colors.courseCardBackground)
.cornerRadius(8)
.shadow(color: Theme.Colors.courseCardShadow, radius: 4, x: 0, y: 3)
.padding(20)
}

@ViewBuilder
var verticalLayout: some View {
VStack(alignment: .leading, spacing: 0) {
Group {
courseBanner
.frame(height: 140)
.clipped()
ProgressLineView(progressEarned: progressEarned, progressPossible: progressPossible)
courseTitle
}
.onTapGesture {
openCourseAction()
}
assignments
}
}

@ViewBuilder
var horizontalLayout: some View {
HStack(alignment: .top, spacing: 0) {
VStack(alignment: .leading, spacing: 0) {
Group {
GeometryReader { proxy in
courseBanner
ProgressLineView(progressEarned: progressEarned, progressPossible: progressPossible)
.frame(width: proxy.size.width)
.clipped()
}
ProgressLineView(progressEarned: progressEarned, progressPossible: progressPossible)
}
.onTapGesture {
openCourseAction()
}
VStack(alignment: .leading, spacing: 0) {
ZStack(alignment: .leading) {
courseTitle
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
.background(
Theme.Colors.background // need for tap area
)

.onTapGesture {
openCourseAction()
}
assignments
}
}
.background(Theme.Colors.courseCardBackground)
.cornerRadius(8)
.shadow(color: Theme.Colors.courseCardShadow, radius: 4, x: 0, y: 3)
.padding(20)
.frame(minHeight: 240)
}

private var assignments: some View {
Expand Down Expand Up @@ -223,8 +269,6 @@ public struct PrimaryCardView: View {
.onFailureImage(CoreAssets.noCourseImage.image)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(height: 140)
.clipped()
.accessibilityElement(children: .ignore)
.accessibilityIdentifier("course_image")
}
Expand Down

0 comments on commit 6267364

Please sign in to comment.