-
Notifications
You must be signed in to change notification settings - Fork 15
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
[ios] pull down InstructionView handle to show remaining steps #276
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import FerrostarCoreFFI | ||
import Foundation | ||
|
||
public protocol TestFixtureFactory { | ||
associatedtype Output | ||
func build(_ n: Int) -> Output | ||
} | ||
|
||
public extension TestFixtureFactory { | ||
func buildMany(_ n: Int) -> [Output] { | ||
(0 ... n).map { build($0) } | ||
} | ||
} | ||
|
||
public struct VisualInstructionContentFactory: TestFixtureFactory { | ||
public init() {} | ||
|
||
public var textBuilder: (Int) -> String = { n in RoadNameFactory().build(n) } | ||
public func text(_ builder: @escaping (Int) -> String) -> Self { | ||
var copy = self | ||
copy.textBuilder = builder | ||
return copy | ||
} | ||
|
||
public func build(_ n: Int = 0) -> VisualInstructionContent { | ||
VisualInstructionContent( | ||
text: textBuilder(n), | ||
maneuverType: .turn, | ||
maneuverModifier: .left, | ||
roundaboutExitDegrees: nil | ||
) | ||
} | ||
} | ||
|
||
public struct VisualInstructionFactory: TestFixtureFactory { | ||
public init() {} | ||
|
||
public var primaryContentBuilder: (Int) -> VisualInstructionContent = { n in | ||
VisualInstructionContentFactory().build(n) | ||
} | ||
|
||
public var secondaryContentBuilder: (Int) -> VisualInstructionContent? = { _ in nil } | ||
|
||
public func secondaryContent(_ builder: @escaping (Int) -> VisualInstructionContent) -> Self { | ||
var copy = self | ||
copy.secondaryContentBuilder = builder | ||
return copy | ||
} | ||
|
||
public func build(_ n: Int = 0) -> VisualInstruction { | ||
VisualInstruction( | ||
primaryContent: primaryContentBuilder(n), | ||
secondaryContent: secondaryContentBuilder(n), | ||
triggerDistanceBeforeManeuver: 42.0 | ||
) | ||
} | ||
} | ||
|
||
public struct RouteStepFactory: TestFixtureFactory { | ||
public init() {} | ||
public var visualInstructionBuilder: (Int) -> VisualInstruction = { n in VisualInstructionFactory().build(n) } | ||
public var roadNameBuilder: (Int) -> String = { n in RoadNameFactory().build(n) } | ||
|
||
public func build(_ n: Int = 0) -> RouteStep { | ||
RouteStep( | ||
geometry: [], | ||
distance: 100, | ||
duration: 99, | ||
roadName: roadNameBuilder(n), | ||
instruction: "Walk west on \(roadNameBuilder(n))", | ||
visualInstructions: [visualInstructionBuilder(n)], | ||
spokenInstructions: [] | ||
) | ||
} | ||
} | ||
|
||
public struct RoadNameFactory: TestFixtureFactory { | ||
public init() {} | ||
public var baseNameBuilder: (Int) -> String = { _ in "Ave" } | ||
|
||
public func baseName(_ builder: @escaping (Int) -> String) -> Self { | ||
var copy = self | ||
copy.baseNameBuilder = builder | ||
return copy | ||
} | ||
|
||
public func build(_ n: Int = 0) -> String { | ||
let numberFormatter = NumberFormatter() | ||
numberFormatter.numberStyle = .ordinal | ||
return "\(numberFormatter.string(from: NSNumber(value: n + 1))!) \(baseNameBuilder(n))" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ struct PortraitNavigationOverlayView: View, CustomizableNavigatingInnerGridView | |
|
||
var speedLimit: Measurement<UnitSpeed>? | ||
var showZoom: Bool | ||
@State | ||
private var instructionsViewSizeWhenNotExpanded: CGSize = .zero | ||
var onZoomIn: () -> Void | ||
var onZoomOut: () -> Void | ||
var showCentering: Bool | ||
|
@@ -45,44 +47,58 @@ struct PortraitNavigationOverlayView: View, CustomizableNavigatingInnerGridView | |
} | ||
|
||
var body: some View { | ||
VStack { | ||
if case let .navigating(_, _, _, _, progress: progress, _, visualInstruction: visualInstruction, | ||
_) = navigationState?.tripState, | ||
ZStack(alignment: .top) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The layout changes here are non-trivial. We want to be able to expand the instruction view over top of the other content when it's expanded. But when it's not expanded, we want it to behave as if it's in a vstack with the NavigationInnerGridView. My solution was to put the InstructionView in a ZStack above the grid, and then plumb out the InstructionView's "unexpanded height" to push down the NavigatingInnerGridView. I struggled a bit with implementing this layout in SwiftUI. It's something I think would be natural to express in old school iOS layout constraints. Maybe there's a better way? |
||
VStack { | ||
Spacer() | ||
|
||
// The inner content is displayed vertically full screen | ||
// when both the visualInstructions and progress are nil. | ||
// It will automatically reduce height if and when either | ||
// view appears | ||
NavigatingInnerGridView( | ||
speedLimit: speedLimit, | ||
showZoom: showZoom, | ||
onZoomIn: onZoomIn, | ||
onZoomOut: onZoomOut, | ||
showCentering: showCentering, | ||
onCenter: onCenter | ||
) | ||
.innerGrid { | ||
topCenter?() | ||
} topTrailing: { | ||
topTrailing?() | ||
} midLeading: { | ||
midLeading?() | ||
} bottomTrailing: { | ||
bottomTrailing?() | ||
} | ||
|
||
if case let .navigating(_, _, _, _, progress: progress, _, _, _) = navigationState?.tripState { | ||
ArrivalView( | ||
progress: progress, | ||
onTapExit: onTapExit | ||
) | ||
} | ||
}.padding(.top, instructionsViewSizeWhenNotExpanded.height) | ||
|
||
if case let .navigating( | ||
_, | ||
_, | ||
remainingSteps: remainingSteps, | ||
_, | ||
progress: progress, | ||
_, | ||
visualInstruction: visualInstruction, | ||
_ | ||
) = navigationState?.tripState, | ||
let visualInstruction | ||
{ | ||
InstructionsView( | ||
visualInstruction: visualInstruction, | ||
distanceFormatter: formatterCollection.distanceFormatter, | ||
distanceToNextManeuver: progress.distanceToNextManeuver | ||
) | ||
} | ||
|
||
// The inner content is displayed vertically full screen | ||
// when both the visualInstructions and progress are nil. | ||
// It will automatically reduce height if and when either | ||
// view appears | ||
NavigatingInnerGridView( | ||
speedLimit: speedLimit, | ||
showZoom: showZoom, | ||
onZoomIn: onZoomIn, | ||
onZoomOut: onZoomOut, | ||
showCentering: showCentering, | ||
onCenter: onCenter | ||
) | ||
.innerGrid { | ||
topCenter?() | ||
} topTrailing: { | ||
topTrailing?() | ||
} midLeading: { | ||
midLeading?() | ||
} bottomTrailing: { | ||
bottomTrailing?() | ||
} | ||
|
||
if case let .navigating(_, _, _, _, progress: progress, _, _, _) = navigationState?.tripState { | ||
ArrivalView( | ||
progress: progress, | ||
onTapExit: onTapExit | ||
distanceToNextManeuver: progress.distanceToNextManeuver, | ||
remainingSteps: remainingSteps, | ||
sizeWhenNotExpanded: $instructionsViewSizeWhenNotExpanded | ||
) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might have gone overboard here, but I expect it to pay dividends to make it easier to create scaffolding data for our previews and unit tests. If you think it's too much, I can inline something less clever for my specific use case.