-
Notifications
You must be signed in to change notification settings - Fork 313
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
NavigationView Hookup #1063
NavigationView Hookup #1063
Changes from all commits
c9ff71d
985488a
2fda6fb
54e93c7
6c7adcc
ed962a6
76da95d
166d64e
1d1dd86
14c0e9c
8341c58
b686a3a
14a2452
f2985a8
8d56abd
2e794a3
9fedf2a
8d5aba5
72cd75f
a6462be
3e8c8ee
2d8aea8
f88104e
b40215b
41401e3
f20fea6
5a45a0a
66f4379
eef330b
32c69f4
bfc905b
de5fd5c
7487af7
0abdb4a
3349d90
cd0c253
c5f0738
ff166b9
35a21bf
a816019
813d7b6
2ea8395
105d1a7
5ad36db
b14321b
d3e6f0e
60f2d4e
bac044d
40ac8de
f48075b
9e50721
54e3618
b64c76b
59c2494
bd926d3
8a73822
3272a5c
86266e0
b725c62
30b3f99
cc8f6b3
0652574
9e3a858
3687e74
cd94b3c
3d54668
2600685
221a8e6
219e1ac
fe3bc05
f2cd852
8af5175
c08faa4
8328ad0
0650ae3
3ffc591
e9f8ac0
895e3cc
e6fd8f4
0c2189e
7277b64
eb7e214
c586760
f0aa930
76b6c15
b55be1e
15a5c66
ec7d6bd
e677fda
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 |
---|---|---|
|
@@ -18,6 +18,9 @@ enum ExampleMode { | |
|
||
class ViewController: UIViewController, MGLMapViewDelegate, CLLocationManagerDelegate, VoiceControllerDelegate { | ||
|
||
// MARK: - Class Constants | ||
static let mapInsets = UIEdgeInsets(top: 25, left: 25, bottom: 25, right: 25) | ||
|
||
// MARK: - IBOutlets | ||
@IBOutlet weak var longPressHintView: UIView! | ||
|
||
|
@@ -91,8 +94,6 @@ class ViewController: UIViewController, MGLMapViewDelegate, CLLocationManagerDel | |
simulationButton.isSelected = true | ||
startButton.isEnabled = false | ||
|
||
setupMapView() | ||
|
||
alertController = UIAlertController(title: "Start Navigation", message: "Select the navigation type", preferredStyle: .actionSheet) | ||
alertController.addAction(UIAlertAction(title: "Default UI", style: .default, handler: { (action) in | ||
self.startBasicNavigation() | ||
|
@@ -120,8 +121,14 @@ class ViewController: UIViewController, MGLMapViewDelegate, CLLocationManagerDel | |
override func viewWillAppear(_ animated: Bool) { | ||
super.viewWillAppear(animated) | ||
|
||
// Reset the navigation styling to the defaults | ||
DayStyle().apply() | ||
//Reload the mapView. | ||
setupMapView() | ||
|
||
// Reset the navigation styling to the defaults if we are returning from a presentation. | ||
if (presentedViewController != nil) { | ||
DayStyle().apply() | ||
} | ||
|
||
} | ||
|
||
// MARK: Gesture Recognizer Handlers | ||
|
@@ -298,21 +305,32 @@ class ViewController: UIViewController, MGLMapViewDelegate, CLLocationManagerDel | |
} | ||
|
||
func setupMapView() { | ||
guard mapView == nil else { return } | ||
mapView = NavigationMapView(frame: view.bounds) | ||
guard self.mapView == nil else { return } | ||
let mapView = NavigationMapView(frame: view.bounds) | ||
self.mapView = mapView | ||
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. maybe if we're explicitly dictating
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. There's actually a reason for this pattern -- |
||
|
||
mapView!.autoresizingMask = [.flexibleWidth, .flexibleHeight] | ||
mapView!.delegate = self | ||
mapView!.navigationMapDelegate = self | ||
mapView!.userTrackingMode = .follow | ||
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. 🎉 |
||
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] | ||
mapView.delegate = self | ||
mapView.navigationMapDelegate = self | ||
mapView.userTrackingMode = .follow | ||
let bottomPadding = (view.frame.height + view.frame.origin.y) - bottomBar.frame.origin.y | ||
|
||
view.insertSubview(mapView!, belowSubview: bottomBar) | ||
var topPadding: CGFloat = 0.0 | ||
if #available(iOS 11.0, *) { | ||
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. There is a convenient 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 is setting up the map inset, not an auto layout constraint. 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.
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. Is this still actionable? 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. @bsudekum @frederoni Looked into this -- bringing the creation of the mapView into storyboard doesn't look like a good idea right now, as the storyboard will likely keep a reference to it while the navigation scene is presented. There may be ways to get around this, but it's non-trivial enough to look out-of-scope for this PR. |
||
topPadding = view.safeAreaInsets.top | ||
} else if let navCon = navigationController { | ||
topPadding = navCon.navigationBar.frame.size.height | ||
} | ||
|
||
let subviewMask = UIEdgeInsets(top: topPadding, left: 0, bottom: bottomPadding, right: 0) | ||
mapView.contentInset = ViewController.mapInsets + subviewMask | ||
|
||
view.insertSubview(mapView, belowSubview: bottomBar) | ||
|
||
let singleTap = UILongPressGestureRecognizer(target: self, action: #selector(didLongPress(tap:))) | ||
for recognizer in mapView!.gestureRecognizers! where recognizer is UILongPressGestureRecognizer { | ||
singleTap.require(toFail: recognizer) | ||
} | ||
mapView!.addGestureRecognizer(singleTap) | ||
mapView.gestureRecognizers?.filter({ $0 is UILongPressGestureRecognizer }).forEach(singleTap.require(toFail:)) | ||
mapView.addGestureRecognizer(singleTap) | ||
|
||
} | ||
|
||
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) { | ||
|
@@ -414,7 +432,6 @@ extension ViewController: NavigationViewControllerDelegate { | |
// Called when the user hits the exit button. | ||
// If implemented, you are responsible for also dismissing the UI. | ||
func navigationViewControllerDidCancelNavigation(_ navigationViewController: NavigationViewController) { | ||
setupMapView() | ||
navigationViewController.dismiss(animated: true, completion: nil) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Foundation | ||
import UIKit | ||
|
||
extension CGSize: ExpressibleByFloatLiteral { | ||
public typealias FloatLiteralType = Double | ||
|
||
public init(size: Double) { | ||
self.init(width: size, height: size) | ||
} | ||
|
||
public init(floatLiteral value: FloatLiteralType) { | ||
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. Do these need to be public? 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.
|
||
self.init(size: value) | ||
} | ||
} |
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 believe the right way to reset styling to the defaults is use a
styleManager
and probably calltimeOfDayChanged()
... right?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.
This approach won't work because the
ViewController
will always show aDayStyle
theme, regardless of the time-of-day.In reality, the call isn't strictly necessary because the only thing the
DayStyle
does that affects theViewController
is that it changes the style of the status bar, a thing we could do directly. But I digress.