Skip to content

Commit

Permalink
feat: use managed navigation path (#113)
Browse files Browse the repository at this point in the history
* feat: use managed navigation path

* fix test
  • Loading branch information
boringcactus authored Apr 4, 2024
1 parent 7a6ed82 commit 09f7f5d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
4 changes: 4 additions & 0 deletions iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
8C84D33E2B5AEE0200192C0A /* NearbyTransitView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C84D33D2B5AEE0200192C0A /* NearbyTransitView.swift */; };
8CC1BB402B59D1F6005386FE /* LocationDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CC1BB3F2B59D1F6005386FE /* LocationDataManager.swift */; };
8CD1F8CD2B7164C100F419D4 /* PredictionsFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CD1F8CC2B7164C100F419D4 /* PredictionsFetcher.swift */; };
8CE0141B2BBF059B00918FAE /* SheetNavigationStackEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CE0141A2BBF059A00918FAE /* SheetNavigationStackEntry.swift */; };
8CEA10232BA0F3C6001C6EB9 /* ScheduleFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CEA10222BA0F3C6001C6EB9 /* ScheduleFetcher.swift */; };
8CEA10252BA4B179001C6EB9 /* AlertsFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CEA10242BA4B179001C6EB9 /* AlertsFetcher.swift */; };
8CEA10272BA4C83D001C6EB9 /* AlertsFetcherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CEA10262BA4C83D001C6EB9 /* AlertsFetcherTests.swift */; };
Expand Down Expand Up @@ -158,6 +159,7 @@
8C84D33D2B5AEE0200192C0A /* NearbyTransitView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NearbyTransitView.swift; sourceTree = "<group>"; };
8CC1BB3F2B59D1F6005386FE /* LocationDataManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationDataManager.swift; sourceTree = "<group>"; };
8CD1F8CC2B7164C100F419D4 /* PredictionsFetcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PredictionsFetcher.swift; sourceTree = "<group>"; };
8CE0141A2BBF059A00918FAE /* SheetNavigationStackEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SheetNavigationStackEntry.swift; sourceTree = "<group>"; };
8CEA10222BA0F3C6001C6EB9 /* ScheduleFetcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScheduleFetcher.swift; sourceTree = "<group>"; };
8CEA10242BA4B179001C6EB9 /* AlertsFetcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertsFetcher.swift; sourceTree = "<group>"; };
8CEA10262BA4C83D001C6EB9 /* AlertsFetcherTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertsFetcherTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -509,6 +511,7 @@
9A37F3062BACCCA5001714FE /* CoordinateExtension.swift */,
9ADB849C2BAD05BC006581CE /* Inspection.swift */,
9ADB84A12BAE37C0006581CE /* StopExtension.swift */,
8CE0141A2BBF059A00918FAE /* SheetNavigationStackEntry.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -860,6 +863,7 @@
9A2005C92B97B65900F562E1 /* NearbyStopRoutePatternView.swift in Sources */,
9A4E8E592B7EC4B90066B936 /* RoutePill.swift in Sources */,
9A5B27562BB221C1009A6FC6 /* RouteLayerGenerator.swift in Sources */,
8CE0141B2BBF059B00918FAE /* SheetNavigationStackEntry.swift in Sources */,
8C5054582BB5EB6C00C6A51C /* StopDetailsPage.swift in Sources */,
9A9E05F42B6D6DEA0086B437 /* SearchResultFetcher.swift in Sources */,
ED3581682BB470C4005DDC34 /* PartialSheetDetent.swift in Sources */,
Expand Down
10 changes: 8 additions & 2 deletions iosApp/iosApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct ContentView: View {
@EnvironmentObject var socketProvider: SocketProvider
@EnvironmentObject var viewportProvider: ViewportProvider
@State private var sheetHeight: CGFloat = .zero
@State private var navigationStack: [SheetNavigationStackEntry] = []

private var sheetDetents: Set<PartialSheetDetent> {
if #available(iOS 16, *) {
Expand Down Expand Up @@ -57,11 +58,16 @@ struct ContentView: View {
)
.ignoresSafeArea(edges: .bottom)
.sheet(isPresented: .constant(true)) {
NavigationStack {
NavigationStack(path: $navigationStack) {
nearbyTransit
.navigationBarHidden(true)
.navigationDestination(for: SheetNavigationStackEntry.self) { entry in
switch entry {
case let .stopDetails(stop, route):
StopDetailsPage(stop: stop, route: route)
}
}
}
.navigationViewStyle(.stack)
.partialSheetDetents(
sheetDetents,
largestUndimmedDetent: .medium
Expand Down
4 changes: 1 addition & 3 deletions iosApp/iosApp/Pages/NearbyTransit/NearbyStopView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ struct NearbyStopView: View {

var body: some View {
VStack(alignment: .leading) {
NavigationLink {
StopDetailsPage(stop: patternsAtStop.stop, route: patternsAtStop.route)
} label: {
NavigationLink(value: SheetNavigationStackEntry.stopDetails(patternsAtStop.stop, patternsAtStop.route)) {
Text(patternsAtStop.stop.name).fontWeight(.bold)
}

Expand Down
4 changes: 2 additions & 2 deletions iosApp/iosApp/Pages/StopDetails/StopDetailsPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import SwiftUI

struct StopDetailsPage: View {
var stop: Stop
var route: Route
var route: Route?

var body: some View {
Text("Stop: \(stop.name)")
.navigationTitle("Stop Details")
Text("Route: \(route.longName)")
Text("Route: \(route?.longName ?? "-")")
}
}

Expand Down
14 changes: 14 additions & 0 deletions iosApp/iosApp/Utils/SheetNavigationStackEntry.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// SheetNavigationStackEntry.swift
// iosApp
//
// Created by Horn, Melody on 2024-04-04.
// Copyright © 2024 MBTA. All rights reserved.
//

import Foundation
import shared

enum SheetNavigationStackEntry: Hashable {
case stopDetails(Stop, Route?)
}
4 changes: 1 addition & 3 deletions iosApp/iosAppTests/Views/NearbyTransitViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,6 @@ final class NearbyTransitViewTests: XCTestCase {
patternsByHeadsign: [PatternsByHeadsign(route: route, headsign: "Place", patterns: [], upcomingTrips: nil, alertsHere: nil)]
), now: Date.now.toKotlinInstant())

let stopDetailsPage = try sut.inspect().find(navigationLink: "This Stop").view(StopDetailsPage.self).actualView()
XCTAssertEqual(stopDetailsPage.stop, stop)
XCTAssertEqual(stopDetailsPage.route, route)
XCTAssertEqual(try sut.inspect().find(navigationLink: "This Stop").value(SheetNavigationStackEntry.self), .stopDetails(stop, route))
}
}

0 comments on commit 09f7f5d

Please sign in to comment.