-
Notifications
You must be signed in to change notification settings - Fork 315
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
Enable night style when inside tunnel #1127
Changes from 58 commits
d2581fc
0a67127
52564d6
2f67660
72fee83
1b0e577
14c5b8e
d764421
dc482f7
1b1152a
19ac74d
f81319b
aadadf4
181b428
5198ce4
b2b0186
05ef98f
bb89fff
613fdfc
8caa01a
c1d95d5
efc7527
256e154
7686d52
b8f8a9e
cf306ca
c7513bf
fb959c8
6915af5
e5058e6
f7463d4
232baa4
64a7897
4e5356a
be3cf6b
18160da
af050d4
e48ad83
3d1ef3f
da0ab08
82c8310
4518a12
49a5817
2b5cd86
f25448f
59b25b3
0b93231
f71f649
8f24774
0b44f03
3675974
2acde88
241bba6
4ad24d0
6ef815c
f0411b8
5ecb164
36a374a
cb8a46b
709231e
70c5e76
9c878c3
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 |
---|---|---|
|
@@ -388,21 +388,39 @@ open class RouteStepProgress: NSObject { | |
/** | ||
The next intersection the user will travel through. | ||
|
||
The step must contains `Intersections` for this value not be `nil`. | ||
The step must contain `intersectionsIncludingUpcomingManeuverIntersection` otherwise this property will be `nil`. | ||
*/ | ||
@objc public var upcomingIntersection: Intersection? { | ||
guard let intersections = intersectionsIncludingUpcomingManeuverIntersection, intersectionIndex + 1 < intersections.endIndex else { | ||
guard let intersections = intersectionsIncludingUpcomingManeuverIntersection, intersections.startIndex...intersections.endIndex-2 ~= intersectionIndex else { | ||
return nil | ||
} | ||
|
||
return intersections[intersectionIndex] | ||
return intersections[intersections.index(after: intersectionIndex)] | ||
} | ||
|
||
/** | ||
Index representing the current intersection. | ||
*/ | ||
@objc public var intersectionIndex: Int = 0 | ||
|
||
/** | ||
The current intersection the user will travel through. | ||
|
||
The step must contain `intersectionsIncludingUpcomingManeuverIntersection` otherwise this property will be `nil`. | ||
*/ | ||
@objc public var currentIntersection: Intersection? { | ||
guard let intersections = intersectionsIncludingUpcomingManeuverIntersection, intersections.startIndex..<intersections.endIndex ~= intersectionIndex else { | ||
return nil | ||
} | ||
|
||
return intersections[intersectionIndex] | ||
} | ||
|
||
/** | ||
Returns an array of the calculated distances from the current intersection to the next intersection on the current step. | ||
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. Nit: this is a property, not a method, so it is set to the array rather than returning the array. |
||
*/ | ||
@objc public var intersectionDistances = [CLLocationDistance]() | ||
|
||
/** | ||
The distance in meters the user is to the next intersection they will pass through. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -304,6 +304,11 @@ public class NavigationViewController: UIViewController { | |
*/ | ||
@objc public var annotatesSpokenInstructions = false | ||
|
||
/** | ||
A Boolean value that indicates whether the dark style should apply when a route controller enters a tunnel. | ||
*/ | ||
@objc public var enableNightStyleInsideTunnelFeatureEnabled: Bool = false | ||
|
||
let progressBar = ProgressBar() | ||
var styleManager: StyleManager! | ||
|
||
|
@@ -403,6 +408,16 @@ public class NavigationViewController: UIViewController { | |
let secondsRemaining = routeProgress.currentLegProgress.currentStepProgress.durationRemaining | ||
|
||
mapViewController?.notifyDidChange(routeProgress: routeProgress, location: location, secondsRemaining: secondsRemaining) | ||
|
||
if enableNightStyleInsideTunnelFeatureEnabled, | ||
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. This property has the word 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. |
||
let currentIntersection = routeProgress.currentLegProgress.currentStepProgress.currentIntersection, | ||
let classes = currentIntersection.outletRoadClasses { | ||
if classes.contains(.tunnel) { | ||
styleManager.applyStyle(type:.nightStyle) | ||
} else { | ||
styleManager.timeOfDayChanged() | ||
} | ||
} | ||
|
||
progressBar.setProgress(routeProgress.currentLegProgress.userHasArrivedAtWaypoint ? 1 : CGFloat(routeProgress.fractionTraveled), animated: true) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,22 @@ open class StyleManager: NSObject { | |
resetTimeOfDayTimer() | ||
} | ||
|
||
func applyStyle(type styleType: StyleType) { | ||
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. Could this func be combined with the 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. Yes, I considered it. However, this func 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.
|
||
guard currentStyleType != styleType else { return } | ||
|
||
NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(timeOfDayChanged), object: nil) | ||
|
||
for style in styles { | ||
if style.styleType == styleType { | ||
style.apply() | ||
currentStyleType = styleType | ||
delegate?.styleManager?(self, didApply: style) | ||
} | ||
} | ||
|
||
forceRefreshAppearance() | ||
} | ||
|
||
func applyStyle() { | ||
guard let location = delegate?.locationFor(styleManager: self) else { | ||
// We can't calculate sunset or sunrise w/o a location so just apply the first style | ||
|
@@ -116,14 +132,7 @@ open class StyleManager: NSObject { | |
} | ||
|
||
let styleTypeForTimeOfDay = styleType(for: location) | ||
|
||
for style in styles { | ||
if style.styleType == styleTypeForTimeOfDay { | ||
style.apply() | ||
currentStyleType = style.styleType | ||
delegate?.styleManager?(self, didApply: style) | ||
} | ||
} | ||
applyStyle(type: styleTypeForTimeOfDay) | ||
} | ||
|
||
func styleType(for location: CLLocation) -> StyleType { | ||
|
@@ -144,7 +153,10 @@ open class StyleManager: NSObject { | |
} | ||
|
||
applyStyle() | ||
|
||
forceRefreshAppearance() | ||
} | ||
|
||
func forceRefreshAppearance() { | ||
for window in UIApplication.shared.windows { | ||
for view in window.subviews { | ||
view.removeFromSuperview() | ||
|
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.
If the user has set
NavigationViewController.automaticallyChangeStyleForTunnel
to false, is it necessary to perform these calculations?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.
@bsudekum FYI
intersectionIndex
- fix for issue Intersection index is always 0 #1170. @1ec5 do you need to use this fix for a task unrelated to dead reckoning?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.
@vincethecoder I don't think this code should be intertwined with
isDeadReckoningEnabled
. Let's keep these as separate ideas for now.IMO, the fix here is to move
NavigationViewController.automaticallyChangeStyleForTunnel
toRouteController
and rename it to something more appropriate.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.
@bsudekum I believe it was mentioned in one of my PR comments to separate the UI-related things in
NavigationViewController
fromRouteController
. Now, I'm totally thrown for loop 🤔cc @1ec5 - do you recall this discussion?
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.
Yes, in #1127 (comment) I recommended keeping UI-related stuff out of Core Navigation. I stand by that recommendation.