-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from OneBusAway/modify-trip-planner-view
Modify Itinerary View
- Loading branch information
Showing
14 changed files
with
287 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,29 @@ | ||
// | ||
// ItineraryLegUnknownView.swift | ||
// OTPKit | ||
// | ||
// Created by Aaron Brethorst on 8/5/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// Represents an itinerary leg that uses an unknown method of conveyance. | ||
struct ItineraryLegUnknownView: View { | ||
let leg: Leg | ||
|
||
var body: some View { | ||
HStack(spacing: 4) { | ||
Text("\(leg.mode): \(Formatters.formatTimeDuration(leg.duration))") | ||
} | ||
.padding(.horizontal, 8) | ||
.padding(.vertical, 4) | ||
.background(Color.gray.opacity(0.2)) | ||
.foregroundStyle(.gray) | ||
.clipShape(RoundedRectangle(cornerRadius: 8)) | ||
.frame(height: 40) | ||
} | ||
} | ||
|
||
#Preview { | ||
ItineraryLegUnknownView(leg: PreviewHelpers.buildLeg()) | ||
} |
This file contains 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,53 @@ | ||
// | ||
// ItineraryLegVehicleView.swift | ||
// OTPKit | ||
// | ||
// Created by Aaron Brethorst on 8/5/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// Represents an itinerary leg that uses a vehicular method of conveyance. | ||
struct ItineraryLegVehicleView: View { | ||
let leg: Leg | ||
|
||
var body: some View { | ||
HStack(spacing: 4) { | ||
Text(leg.route ?? "") | ||
.padding(.horizontal, 8) | ||
.padding(.vertical, 4) | ||
.background(backgroundColor) | ||
.foregroundStyle(.foreground) | ||
.font(.caption) | ||
.clipShape(RoundedRectangle(cornerRadius: 4)) | ||
|
||
Image(systemName: imageName) | ||
.foregroundStyle(.foreground) | ||
}.frame(height: 40) | ||
} | ||
|
||
private var imageName: String { | ||
if leg.mode == "TRAM" { | ||
return "tram" | ||
} else if leg.mode == "BUS" { | ||
return "bus" | ||
} else { | ||
return "" | ||
} | ||
} | ||
|
||
private var backgroundColor: Color { | ||
if leg.mode == "TRAM" { | ||
return Color.blue | ||
} else if leg.mode == "BUS" { | ||
return Color.green | ||
} else { | ||
return Color.pink | ||
} | ||
} | ||
|
||
} | ||
|
||
#Preview { | ||
ItineraryLegVehicleView(leg: PreviewHelpers.buildLeg()) | ||
} |
This file contains 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,30 @@ | ||
// | ||
// ItineraryLegWalkView.swift | ||
// OTPKit | ||
// | ||
// Created by Aaron Brethorst on 8/5/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// Represents an itinerary leg that uses a walking method of conveyance. | ||
struct ItineraryLegWalkView: View { | ||
let leg: Leg | ||
|
||
var body: some View { | ||
HStack(spacing: 4) { | ||
Image(systemName: "figure.walk") | ||
Text(Formatters.formatTimeDuration(leg.duration)) | ||
} | ||
.padding(.horizontal, 8) | ||
.padding(.vertical, 4) | ||
.background(Color.gray.opacity(0.2)) | ||
.foregroundStyle(.gray) | ||
.clipShape(RoundedRectangle(cornerRadius: 8)) | ||
.frame(height: 40) | ||
} | ||
} | ||
|
||
#Preview { | ||
ItineraryLegWalkView(leg: PreviewHelpers.buildLeg()) | ||
} |
This file contains 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 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 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,45 @@ | ||
// | ||
// FlowLayout.swift | ||
// OTPKit | ||
// | ||
// Created by Hilmy Veradin on 04/08/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// Extension to make adaptive layout | ||
struct FlowLayout: Layout { | ||
func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache _: inout ()) -> CGSize { | ||
let sizes = subviews.map { $0.sizeThatFits(.unspecified) } | ||
return layout(sizes: sizes, proposal: proposal).size | ||
} | ||
|
||
func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache _: inout ()) { | ||
let sizes = subviews.map { $0.sizeThatFits(.unspecified) } | ||
let offsets = layout(sizes: sizes, proposal: proposal).offsets | ||
|
||
for (offset, subview) in zip(offsets, subviews) { | ||
subview.place(at: CGPoint(x: bounds.minX + offset.x, y: bounds.minY + offset.y), proposal: .unspecified) | ||
} | ||
} | ||
|
||
private func layout(sizes: [CGSize], proposal: ProposedViewSize) -> (offsets: [CGPoint], size: CGSize) { | ||
let verticalSpacing: CGFloat = 4 | ||
let horizontalSpacing: CGFloat = 8 | ||
var result: [CGPoint] = [] | ||
var currentPosition: CGPoint = .zero | ||
var maxY: CGFloat = 0 | ||
|
||
for size in sizes { | ||
if currentPosition.x + size.width > (proposal.width ?? .infinity) { | ||
currentPosition.x = 0 | ||
currentPosition.y = maxY + verticalSpacing | ||
} | ||
result.append(currentPosition) | ||
currentPosition.x += size.width + horizontalSpacing | ||
maxY = max(maxY, currentPosition.y + size.height) | ||
} | ||
|
||
return (result, CGSize(width: proposal.width ?? .infinity, height: maxY)) | ||
} | ||
} |
Oops, something went wrong.