-
Notifications
You must be signed in to change notification settings - Fork 12
BER-71: Rewrite GymDetailViewController in SwiftUIFeature #363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
YHC66
wants to merge
9
commits into
master
Choose a base branch
from
feature-ber-71
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+366
−139
Open
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d2de5cc
Gymdetailview rewrite
YHC66 e7b9476
Update GymDetailSwiftUIView.swift
YHC66 6116dd0
Update gymdetailview
YHC66 9a444fe
Refactor components
YHC66 7dfa210
fix Constant.doegladeimage
YHC66 a1e9e40
Delete and Rename file
YHC66 d6528ca
Update UI and Refactor overview
YHC66 52bcdf9
Refactor overview card; minor fixes
YHC66 ce3e28f
Create separate files for views
YHC66 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,209 @@ | ||
| // | ||
| // GymDetailView.swift | ||
| // | ||
| // Created by Yihang Chen on 4/9/25. | ||
| // Copyright © 2025 ASUC OCTO. All rights reserved. | ||
| // | ||
|
|
||
| import SwiftUI | ||
|
|
||
| struct CategoryOverviewCard: View { | ||
| let category: SearchItem & HasLocation & HasImage | ||
|
|
||
| var body: some View { | ||
| HStack(alignment: .top, spacing: 16) { | ||
| VStack(alignment: .leading) { | ||
| TitleView(name: category.name) | ||
|
|
||
| Spacer(minLength: 20) | ||
|
|
||
| ContactInfoView(category: category) | ||
| } | ||
|
|
||
| Spacer() | ||
|
|
||
| ImageView(imageURL: category.imageURL) | ||
| } | ||
| .padding(12) | ||
| .background(Color(BMColor.cardBackground)) | ||
| .cornerRadius(12) | ||
| .shadow(color: Color(uiColor: .label).opacity(0.15), radius: 5, x: 0, y: 0) | ||
| .padding(.vertical, 8) | ||
| .padding(.horizontal, 4) | ||
| } | ||
|
|
||
| struct TitleView: View { | ||
| let name: String | ||
|
|
||
| var body: some View { | ||
| Text(name) | ||
| .font(Font(BMFont.bold(23))) | ||
| .foregroundColor(Color(BMColor.blackText)) | ||
| .lineLimit(3) | ||
| .padding(.top, 8) | ||
| } | ||
| } | ||
|
|
||
| struct ContactInfoView: View { | ||
| let category: SearchItem & HasLocation | ||
|
|
||
| var body: some View { | ||
| VStack(alignment: .leading, spacing: 12) { | ||
| if let address = category.address, !address.isEmpty { | ||
| ContactInfoRow( | ||
| iconName: "location.fill", | ||
| text: address, | ||
| lineLimit: nil | ||
| ) | ||
| } | ||
|
|
||
| if let hasPhone = category as? HasPhoneNumber, | ||
| let phoneNumber = hasPhone.phoneNumber, | ||
| !phoneNumber.isEmpty { | ||
| ContactInfoRow( | ||
| iconName: "phone.fill", | ||
| text: phoneNumber | ||
| ) | ||
| } | ||
|
|
||
| if let distance = category.distanceToUser { | ||
| ContactInfoRow( | ||
| iconName: "figure.walk", | ||
| text: String(format: "%.1f miles", distance) | ||
| ) | ||
| } | ||
| } | ||
| .foregroundColor(Color(BMColor.blackText)) | ||
| } | ||
| } | ||
|
|
||
| struct ContactInfoRow: View { | ||
| let iconName: String | ||
| let text: String | ||
| var lineLimit: Int? = 1 | ||
|
|
||
| var body: some View { | ||
| HStack(alignment: .top, spacing: 10) { | ||
| Image(systemName: iconName) | ||
| .frame(width: 18, height: 18) | ||
|
|
||
| Text(text) | ||
| .font(Font(BMFont.light(12))) | ||
| .lineLimit(lineLimit) | ||
| .fixedSize(horizontal: false, vertical: true) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| struct ImageView: View { | ||
| let imageURL: URL? | ||
|
|
||
| var body: some View { | ||
| if let imageURL = imageURL { | ||
| AsyncImage(url: imageURL) { phase in | ||
| switch phase { | ||
| case .empty: | ||
| defaultImage | ||
| case .success(let image): | ||
| image | ||
| .resizable() | ||
| .aspectRatio(contentMode: .fill) | ||
| .frame(width: 120, height: 200) | ||
| .clipShape(RoundedRectangle(cornerRadius: 8)) | ||
| .overlay( | ||
| RoundedRectangle(cornerRadius: 8) | ||
| .stroke(Color(uiColor: .systemGray4), lineWidth: 0.5) | ||
| ) | ||
| case .failure: | ||
| defaultImage | ||
| @unknown default: | ||
| EmptyView() | ||
| } | ||
| } | ||
| } else { | ||
| defaultImage | ||
| } | ||
| } | ||
YHC66 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| private var defaultImage: some View { | ||
| Image(uiImage: Constants.doeGladeImage) | ||
| .resizable() | ||
| .aspectRatio(contentMode: .fill) | ||
| .frame(width: 120, height: 200) | ||
| .clipShape(RoundedRectangle(cornerRadius: 8)) | ||
| .overlay( | ||
| RoundedRectangle(cornerRadius: 8) | ||
| .stroke(Color(uiColor: .systemGray4), lineWidth: 0.5) | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| struct GymDetailView: View { | ||
| @Environment(\.openURL) private var openURL | ||
|
|
||
| let gym: Gym | ||
| init(gym: Gym) { | ||
| self.gym = gym | ||
| } | ||
|
|
||
| var body: some View { | ||
| ScrollView { | ||
| VStack(spacing: 16) { | ||
| CategoryOverviewCard(category: gym) | ||
|
|
||
| if gym.weeklyHours != nil { | ||
| OpenTimesCardSwiftUIView(item: gym) | ||
| } | ||
|
|
||
| if let website = gym.website { | ||
| BMActionButton(title: "Learn More") { | ||
| openURL(website) | ||
| } | ||
| } | ||
|
|
||
| if let description = gym.description, !description.isEmpty { | ||
| descriptionCard(description: description) | ||
| } | ||
| } | ||
| .padding(.horizontal, 16) | ||
| .padding(.vertical, 5) | ||
| } | ||
| .navigationTitle(gym.name) | ||
| } | ||
|
|
||
| private func descriptionCard(description: String) -> some View { | ||
| VStack(alignment: .leading, spacing: 10) { | ||
| Text("Description") | ||
| .font(Font(BMFont.bold(16))) | ||
| .foregroundColor(Color(BMColor.blackText)) | ||
|
|
||
| Text(description) | ||
| .font(Font(BMFont.light(12))) | ||
| .foregroundColor(Color(BMColor.blackText)) | ||
| } | ||
YHC66 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .padding(16) | ||
| .frame(maxWidth: .infinity, alignment: .leading) | ||
| .background(Color(BMColor.cardBackground)) | ||
| .cornerRadius(12) | ||
| } | ||
YHC66 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| #Preview { | ||
| let sampleGym = Gym( | ||
| name: "RSF (Recreational Sports Facility)", | ||
| description: "The Recreational Sports Facility (RSF) is UC Berkeley's largest fitness center, offering state-of-the-art equipment, group exercise classes, and various sports courts. Located at the heart of campus, it provides comprehensive fitness options for students and faculty.", | ||
| address: "2301 Bancroft Way, Berkeley, CA 94720", | ||
| phoneNumber: "(510) 111-2222", | ||
| imageLink: nil, | ||
| weeklyHours: nil, | ||
| link: "https://recsports.berkeley.edu/rsf/" | ||
| ) | ||
|
|
||
| sampleGym.latitude = 37.8687 | ||
| sampleGym.longitude = -122.2614 | ||
|
|
||
| return NavigationView { | ||
| GymDetailView(gym: sampleGym) | ||
| } | ||
YHC66 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.