From 2692fd53b64ffd2ff274f4f628a538d2a4736a83 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Tue, 14 Aug 2018 14:52:33 -0700 Subject: [PATCH 01/15] Make FeedbackViewController public --- Cartfile.resolved | 2 +- Examples/Swift/Base.lproj/Main.storyboard | 9 ++ Examples/Swift/CustomViewController.swift | 11 +++ MapboxNavigation/FeedbackItem.swift | 2 +- MapboxNavigation/FeedbackViewController.swift | 94 ++++++++++++++----- MapboxNavigation/RouteMapViewController.swift | 43 +-------- 6 files changed, 96 insertions(+), 65 deletions(-) diff --git a/Cartfile.resolved b/Cartfile.resolved index d7f42028e9..bdb40894f7 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -3,7 +3,7 @@ github "Quick/Nimble" "v7.1.3" github "Quick/Quick" "v1.3.1" github "ceeK/Solar" "2.1.0" github "mapbox/MapboxDirections.swift" "v0.22.0" -github "mapbox/mapbox-events-ios" "v0.4.3" +github "mapbox/mapbox-events-ios" "v0.4.51" github "mapbox/mapbox-voice-swift" "v0.0.1" github "mapbox/turf-swift" "v0.2.0" github "raphaelmor/Polyline" "v4.2.0" diff --git a/Examples/Swift/Base.lproj/Main.storyboard b/Examples/Swift/Base.lproj/Main.storyboard index c95a0ae6c5..9e81e4f0e9 100644 --- a/Examples/Swift/Base.lproj/Main.storyboard +++ b/Examples/Swift/Base.lproj/Main.storyboard @@ -187,6 +187,13 @@ + @@ -196,6 +203,7 @@ + @@ -204,6 +212,7 @@ + diff --git a/Examples/Swift/CustomViewController.swift b/Examples/Swift/CustomViewController.swift index c30715fa35..73e21fd507 100644 --- a/Examples/Swift/CustomViewController.swift +++ b/Examples/Swift/CustomViewController.swift @@ -22,6 +22,13 @@ class CustomViewController: UIViewController, MGLMapViewDelegate { @IBOutlet var mapView: NavigationMapView! @IBOutlet weak var cancelButton: UIButton! @IBOutlet weak var instructionsBannerView: InstructionsBannerView! + + lazy var feedbackViewController: FeedbackViewController = { + let controller = FeedbackViewController(for: routeController.eventsManager) + controller.modalPresentationStyle = .custom + controller.transitioningDelegate = controller + return controller + }() override func viewDidLoad() { super.viewDidLoad() @@ -106,4 +113,8 @@ class CustomViewController: UIViewController, MGLMapViewDelegate { @IBAction func recenterMap(_ sender: Any) { mapView.recenterMap() } + + @IBAction func showFeedback(_ sender: Any) { + present(feedbackViewController, animated: true, completion: nil) + } } diff --git a/MapboxNavigation/FeedbackItem.swift b/MapboxNavigation/FeedbackItem.swift index d2806e8b36..d7b2367821 100644 --- a/MapboxNavigation/FeedbackItem.swift +++ b/MapboxNavigation/FeedbackItem.swift @@ -7,7 +7,7 @@ extension UIImage { } } -struct FeedbackItem { +public struct FeedbackItem { var title: String var image: UIImage var feedbackType: FeedbackType diff --git a/MapboxNavigation/FeedbackViewController.swift b/MapboxNavigation/FeedbackViewController.swift index 1248f1d8bf..81f6791532 100644 --- a/MapboxNavigation/FeedbackViewController.swift +++ b/MapboxNavigation/FeedbackViewController.swift @@ -3,29 +3,25 @@ import MapboxCoreNavigation import AVFoundation extension FeedbackViewController: UIViewControllerTransitioningDelegate { - func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { + public func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { abortAutodismiss() return DismissAnimator() } - func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { + public func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { return PresentAnimator() } - func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? { + public func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? { return interactor.hasStarted ? interactor : nil } } -typealias FeedbackSection = [FeedbackItem] - -class FeedbackViewController: UIViewController, DismissDraggable, UIGestureRecognizerDelegate { - - typealias SendFeedbackHandler = (FeedbackItem) -> Void +@objc(FeedbackViewController) +public class FeedbackViewController: UIViewController, DismissDraggable, UIGestureRecognizerDelegate { - var sendFeedbackHandler: SendFeedbackHandler? + var sendFeedbackHandler: ((FeedbackItem) -> Void)? var dismissFeedbackHandler: (() -> Void)? - var sections = [FeedbackSection]() var activeFeedbackItem: FeedbackItem? static let sceneTitle = NSLocalizedString("FEEDBACK_TITLE", value: "Report Problem", comment: "Title of view controller for sending feedback") @@ -35,6 +31,8 @@ class FeedbackViewController: UIViewController, DismissDraggable, UIGestureRecog let interactor = Interactor() + public var sections: [[FeedbackItem]] = [[.turnNotAllowed, .closure, .reportTraffic, .confusingInstructions, .generalMapError, .badRoute]] + lazy var collectionView: UICollectionView = { let view: UICollectionView = UICollectionView(frame: .zero, collectionViewLayout: flowLayout) view.translatesAutoresizingMaskIntoConstraints = false @@ -71,7 +69,18 @@ class FeedbackViewController: UIViewController, DismissDraggable, UIGestureRecog return fullHeight } - override func viewDidLoad() { + var eventsManager: EventsManager + + public init(for eventsManager: EventsManager) { + self.eventsManager = eventsManager + super.init(nibName: nil, bundle: nil) + } + + required public init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override public func viewDidLoad() { super.viewDidLoad() setupViews() setupConstraints() @@ -80,14 +89,18 @@ class FeedbackViewController: UIViewController, DismissDraggable, UIGestureRecog view.backgroundColor = .white progressBar.barColor = #colorLiteral(red: 0.9347146749, green: 0.5047877431, blue: 0.1419634521, alpha: 1) enableDraggableDismiss() + + let defaults = defaultFeedbackHandlers() //this is done every time to refresh the feedback UUID + sendFeedbackHandler = defaults.send + dismissFeedbackHandler = defaults.dismiss } - override func viewWillAppear(_ animated: Bool) { + override public func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) progressBar.progress = 1 } - override func viewDidAppear(_ animated: Bool) { + override public func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) UIView.animate(withDuration: FeedbackViewController.autoDismissInterval) { @@ -97,7 +110,7 @@ class FeedbackViewController: UIViewController, DismissDraggable, UIGestureRecog enableAutoDismiss() } - override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) { + override public func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) { super.willTransition(to: newCollection, with: coordinator) // Dismiss the feedback view when switching between landscape and portrait mode. @@ -131,7 +144,7 @@ class FeedbackViewController: UIViewController, DismissDraggable, UIGestureRecog dismissFeedbackHandler?() } - func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool { + public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool { // Only respond to touches outside/behind the view let isDescendant = touch.view?.isDescendant(of: view) ?? true return !isDescendant @@ -165,10 +178,48 @@ class FeedbackViewController: UIViewController, DismissDraggable, UIGestureRecog progressBar.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true progressBar.bottomAnchor.constraint(equalTo: view.safeBottomAnchor).isActive = true } + + func defaultFeedbackHandlers(source: FeedbackSource = .user) -> (send: (FeedbackItem) -> Void, dismiss: () -> Void) { + let uuid = eventsManager.recordFeedback() + let send = defaultSendFeedbackHandler(uuid: uuid) + let dismiss = defaultDismissFeedbackHandler(uuid: uuid) + + return (send, dismiss) + } + + func defaultSendFeedbackHandler(source: FeedbackSource = .user, uuid: UUID) -> (FeedbackItem) -> Void { + return { [weak self] (item) in + guard let strongSelf = self else { return } + + // todo, can this be moved as a delegate on this view controller? + //strongSelf.delegate?.mapViewController(strongSelf, didSendFeedbackAssigned: uuid, feedbackType: item.feedbackType) + strongSelf.eventsManager.updateFeedback(uuid: uuid, type: item.feedbackType, source: source, description: nil) + + guard let parent = strongSelf.parent else { + strongSelf.dismiss(animated: true) + return + } + + strongSelf.dismiss(animated: true) { + DialogViewController().present(on: parent) + } + } + } + + func defaultDismissFeedbackHandler(uuid: UUID) -> (() -> Void) { + return { [weak self ] in + guard let strongSelf = self else { return } + + // todo, can this be moved as a delegate on this view controller? + // strongSelf.delegate?.mapViewControllerDidCancelFeedback(strongSelf) + strongSelf.eventsManager.cancelFeedback(uuid: uuid) + strongSelf.dismiss(animated: true, completion: nil) + } + } } extension FeedbackViewController: UICollectionViewDataSource { - func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: FeedbackCollectionViewCell.defaultIdentifier, for: indexPath) as! FeedbackCollectionViewCell let item = sections[indexPath.section][indexPath.row] @@ -179,15 +230,15 @@ extension FeedbackViewController: UICollectionViewDataSource { return cell } - func numberOfSections(in collectionView: UICollectionView) -> Int { + public func numberOfSections(in collectionView: UICollectionView) -> Int { return sections.count } - func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return sections[section].count } - func scrollViewDidScroll(_ scrollView: UIScrollView) { + public func scrollViewDidScroll(_ scrollView: UIScrollView) { // In case the view is scrolled, dismiss the feedback window immediately // and reset the `progressBar` back to a full progress. abortAutodismiss() @@ -196,7 +247,7 @@ extension FeedbackViewController: UICollectionViewDataSource { } extension FeedbackViewController: UICollectionViewDelegate { - func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { abortAutodismiss() let item = sections[indexPath.section][indexPath.row] sendFeedbackHandler?(item) @@ -204,8 +255,7 @@ extension FeedbackViewController: UICollectionViewDelegate { } extension FeedbackViewController: UICollectionViewDelegateFlowLayout { - - func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { + public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { let availableWidth = collectionView.bounds.width // 3 columns and 2 rows in portrait mode. // 6 columns and 1 row in landscape mode. diff --git a/MapboxNavigation/RouteMapViewController.swift b/MapboxNavigation/RouteMapViewController.swift index df48d33ad7..19ac5ae26e 100644 --- a/MapboxNavigation/RouteMapViewController.swift +++ b/MapboxNavigation/RouteMapViewController.swift @@ -27,11 +27,7 @@ class RouteMapViewController: UIViewController { }() lazy var feedbackViewController: FeedbackViewController = { - let controller = FeedbackViewController() - - controller.sections = [ - [.turnNotAllowed, .closure, .reportTraffic, .confusingInstructions, .generalMapError, .badRoute] - ] + let controller = FeedbackViewController(for: routeController.eventsManager) controller.modalPresentationStyle = .custom controller.transitioningDelegate = controller @@ -254,13 +250,7 @@ class RouteMapViewController: UIViewController { func showFeedback(source: FeedbackSource = .user) { guard let parent = parent else { return } - - let controller = feedbackViewController - let defaults = defaultFeedbackHandlers() //this is done every time to refresh the feedback UUID - controller.sendFeedbackHandler = defaults.send - controller.dismissFeedbackHandler = defaults.dismiss - - parent.present(controller, animated: true, completion: nil) + parent.present(feedbackViewController, animated: true, completion: nil) } override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { @@ -426,35 +416,6 @@ class RouteMapViewController: UIViewController { } } - func defaultFeedbackHandlers(source: FeedbackSource = .user) -> (send: FeedbackViewController.SendFeedbackHandler, dismiss: () -> Void) { - let uuid = routeController.eventsManager.recordFeedback() - let send = defaultSendFeedbackHandler(uuid: uuid) - let dismiss = defaultDismissFeedbackHandler(uuid: uuid) - - return (send, dismiss) - } - - func defaultSendFeedbackHandler(source: FeedbackSource = .user, uuid: UUID) -> FeedbackViewController.SendFeedbackHandler { - return { [weak self] (item) in - guard let strongSelf = self, let parent = strongSelf.parent else { return } - - strongSelf.delegate?.mapViewController(strongSelf, didSendFeedbackAssigned: uuid, feedbackType: item.feedbackType) - strongSelf.routeController.eventsManager.updateFeedback(uuid: uuid, type: item.feedbackType, source: source, description: nil) - strongSelf.dismiss(animated: true) { - DialogViewController().present(on: parent) - } - } - } - - func defaultDismissFeedbackHandler(uuid: UUID) -> (() -> Void) { - return { [weak self ] in - guard let strongSelf = self else { return } - strongSelf.delegate?.mapViewControllerDidCancelFeedback(strongSelf) - strongSelf.routeController.eventsManager.cancelFeedback(uuid: uuid) - strongSelf.dismiss(animated: true, completion: nil) - } - } - var contentInsets: UIEdgeInsets { let top = navigationView.instructionsBannerContentView.bounds.height let bottom = navigationView.bottomBannerView.bounds.height From 5dd01cd67e636a09b5a3a632823233175dd025a8 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Tue, 14 Aug 2018 15:02:36 -0700 Subject: [PATCH 02/15] use class --- MapboxNavigation/FeedbackItem.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MapboxNavigation/FeedbackItem.swift b/MapboxNavigation/FeedbackItem.swift index d7b2367821..85ed4a0cbc 100644 --- a/MapboxNavigation/FeedbackItem.swift +++ b/MapboxNavigation/FeedbackItem.swift @@ -7,7 +7,7 @@ extension UIImage { } } -public struct FeedbackItem { +public class FeedbackItem: NSObject { var title: String var image: UIImage var feedbackType: FeedbackType From 194a5b1fe35be64a25cab524f4c3e43694be9775 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Tue, 14 Aug 2018 15:02:52 -0700 Subject: [PATCH 03/15] @objc --- MapboxNavigation/FeedbackItem.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/MapboxNavigation/FeedbackItem.swift b/MapboxNavigation/FeedbackItem.swift index 85ed4a0cbc..977a534e24 100644 --- a/MapboxNavigation/FeedbackItem.swift +++ b/MapboxNavigation/FeedbackItem.swift @@ -7,6 +7,7 @@ extension UIImage { } } +@objc(MBFeedbackItem) public class FeedbackItem: NSObject { var title: String var image: UIImage From bc32b5e75b1921a7e7f53bc20f1f11aacf38844d Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Wed, 15 Aug 2018 08:59:45 -0700 Subject: [PATCH 04/15] Consolidate --- Examples/Swift/CustomViewController.swift | 9 +++------ MapboxNavigation/FeedbackViewController.swift | 6 ++++-- MapboxNavigation/RouteMapViewController.swift | 9 ++------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/Examples/Swift/CustomViewController.swift b/Examples/Swift/CustomViewController.swift index 73e21fd507..b60e2fbe04 100644 --- a/Examples/Swift/CustomViewController.swift +++ b/Examples/Swift/CustomViewController.swift @@ -23,12 +23,7 @@ class CustomViewController: UIViewController, MGLMapViewDelegate { @IBOutlet weak var cancelButton: UIButton! @IBOutlet weak var instructionsBannerView: InstructionsBannerView! - lazy var feedbackViewController: FeedbackViewController = { - let controller = FeedbackViewController(for: routeController.eventsManager) - controller.modalPresentationStyle = .custom - controller.transitioningDelegate = controller - return controller - }() + var feedbackViewController: FeedbackViewController! override func viewDidLoad() { super.viewDidLoad() @@ -38,6 +33,8 @@ class CustomViewController: UIViewController, MGLMapViewDelegate { mapView.delegate = self mapView.compassView.isHidden = true + + feedbackViewController = FeedbackViewController(eventsManager: routeController.eventsManager) // Add listeners for progress updates resumeNotifications() diff --git a/MapboxNavigation/FeedbackViewController.swift b/MapboxNavigation/FeedbackViewController.swift index 81f6791532..29909e0fdf 100644 --- a/MapboxNavigation/FeedbackViewController.swift +++ b/MapboxNavigation/FeedbackViewController.swift @@ -71,9 +71,11 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu var eventsManager: EventsManager - public init(for eventsManager: EventsManager) { + public init(eventsManager: EventsManager) { self.eventsManager = eventsManager super.init(nibName: nil, bundle: nil) + self.modalPresentationStyle = .custom + self.transitioningDelegate = self } required public init?(coder aDecoder: NSCoder) { @@ -195,7 +197,7 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu //strongSelf.delegate?.mapViewController(strongSelf, didSendFeedbackAssigned: uuid, feedbackType: item.feedbackType) strongSelf.eventsManager.updateFeedback(uuid: uuid, type: item.feedbackType, source: source, description: nil) - guard let parent = strongSelf.parent else { + guard let parent = strongSelf.presentingViewController else { strongSelf.dismiss(animated: true) return } diff --git a/MapboxNavigation/RouteMapViewController.swift b/MapboxNavigation/RouteMapViewController.swift index 19ac5ae26e..609307051c 100644 --- a/MapboxNavigation/RouteMapViewController.swift +++ b/MapboxNavigation/RouteMapViewController.swift @@ -26,13 +26,7 @@ class RouteMapViewController: UIViewController { return viewController }() - lazy var feedbackViewController: FeedbackViewController = { - let controller = FeedbackViewController(for: routeController.eventsManager) - - controller.modalPresentationStyle = .custom - controller.transitioningDelegate = controller - return controller - }() + var feedbackViewController: FeedbackViewController! private struct Actions { static let overview: Selector = #selector(RouteMapViewController.toggleOverview(_:)) @@ -111,6 +105,7 @@ class RouteMapViewController: UIViewController { self.init() self.routeController = routeController self.delegate = delegate + feedbackViewController = FeedbackViewController(eventsManager: routeController.eventsManager) automaticallyAdjustsScrollViewInsets = false } From e77d7f4decea43b3cdbe7db0fae10cca8570196b Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Wed, 15 Aug 2018 09:17:24 -0700 Subject: [PATCH 05/15] nscoder --- MapboxNavigation/FeedbackViewController.swift | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/MapboxNavigation/FeedbackViewController.swift b/MapboxNavigation/FeedbackViewController.swift index 29909e0fdf..4452970343 100644 --- a/MapboxNavigation/FeedbackViewController.swift +++ b/MapboxNavigation/FeedbackViewController.swift @@ -74,12 +74,22 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu public init(eventsManager: EventsManager) { self.eventsManager = eventsManager super.init(nibName: nil, bundle: nil) - self.modalPresentationStyle = .custom - self.transitioningDelegate = self + commonInit() + } + + public override func encode(with aCoder: NSCoder) { + aCoder.encode(eventsManager, forKey: "EventsManager") } required public init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") + eventsManager = aDecoder.decodeObject(of: [EventsManager.self], forKey: "EventsManager") as? EventsManager ?? EventsManager(accessToken: nil) + super.init(coder: aDecoder) + commonInit() + } + + func commonInit() { + self.modalPresentationStyle = .custom + self.transitioningDelegate = self } override public func viewDidLoad() { From f9c3b5eae87a6ef9373b2080c7b07ef22c177157 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Mon, 20 Aug 2018 10:03:23 -0700 Subject: [PATCH 06/15] lazy --- Examples/Swift/CustomViewController.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Examples/Swift/CustomViewController.swift b/Examples/Swift/CustomViewController.swift index b60e2fbe04..741680cebf 100644 --- a/Examples/Swift/CustomViewController.swift +++ b/Examples/Swift/CustomViewController.swift @@ -23,7 +23,9 @@ class CustomViewController: UIViewController, MGLMapViewDelegate { @IBOutlet weak var cancelButton: UIButton! @IBOutlet weak var instructionsBannerView: InstructionsBannerView! - var feedbackViewController: FeedbackViewController! + lazy var feedbackViewController: FeedbackViewController = { + return FeedbackViewController(eventsManager: routeController.eventsManager) + }() override func viewDidLoad() { super.viewDidLoad() From b7b79f3778971ea6c3227a7c143342fd949dac0c Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Mon, 20 Aug 2018 14:31:43 -0700 Subject: [PATCH 07/15] No need for this --- Examples/Swift/CustomViewController.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Examples/Swift/CustomViewController.swift b/Examples/Swift/CustomViewController.swift index 741680cebf..538249f62e 100644 --- a/Examples/Swift/CustomViewController.swift +++ b/Examples/Swift/CustomViewController.swift @@ -35,8 +35,6 @@ class CustomViewController: UIViewController, MGLMapViewDelegate { mapView.delegate = self mapView.compassView.isHidden = true - - feedbackViewController = FeedbackViewController(eventsManager: routeController.eventsManager) // Add listeners for progress updates resumeNotifications() From 4fa51577668b46700bbd07ff37f0c45b636427f4 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Mon, 20 Aug 2018 14:41:53 -0700 Subject: [PATCH 08/15] doc, objc --- MapboxNavigation/FeedbackViewController.swift | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/MapboxNavigation/FeedbackViewController.swift b/MapboxNavigation/FeedbackViewController.swift index 4452970343..21f693f84e 100644 --- a/MapboxNavigation/FeedbackViewController.swift +++ b/MapboxNavigation/FeedbackViewController.swift @@ -3,21 +3,24 @@ import MapboxCoreNavigation import AVFoundation extension FeedbackViewController: UIViewControllerTransitioningDelegate { - public func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { + @objc public func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { abortAutodismiss() return DismissAnimator() } - public func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { + @objc public func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { return PresentAnimator() } - public func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? { + @objc public func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? { return interactor.hasStarted ? interactor : nil } } -@objc(FeedbackViewController) +/** + A view controller containing a grid of buttons the user can use to denote an issue their current navigation experience. + */ +@objc(MBFeedbackViewController) public class FeedbackViewController: UIViewController, DismissDraggable, UIGestureRecognizerDelegate { var sendFeedbackHandler: ((FeedbackItem) -> Void)? @@ -31,6 +34,9 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu let interactor = Interactor() + /** + The feedback items that are visible and selectable by the user. + */ public var sections: [[FeedbackItem]] = [[.turnNotAllowed, .closure, .reportTraffic, .confusingInstructions, .generalMapError, .badRoute]] lazy var collectionView: UICollectionView = { @@ -71,7 +77,10 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu var eventsManager: EventsManager - public init(eventsManager: EventsManager) { + /** + Initialize a new FeedbackViewController from an `EventsManager`. + */ + @objc public init(eventsManager: EventsManager) { self.eventsManager = eventsManager super.init(nibName: nil, bundle: nil) commonInit() @@ -151,7 +160,10 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(dismissFeedback), object: nil) } - @objc func dismissFeedback() { + /** + Instantly dismisses the FeedbackViewController if it is currently presented. + */ + @objc public func dismissFeedback() { abortAutodismiss() dismissFeedbackHandler?() } @@ -231,7 +243,7 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu } extension FeedbackViewController: UICollectionViewDataSource { - public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + @objc public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: FeedbackCollectionViewCell.defaultIdentifier, for: indexPath) as! FeedbackCollectionViewCell let item = sections[indexPath.section][indexPath.row] @@ -242,15 +254,15 @@ extension FeedbackViewController: UICollectionViewDataSource { return cell } - public func numberOfSections(in collectionView: UICollectionView) -> Int { + @objc public func numberOfSections(in collectionView: UICollectionView) -> Int { return sections.count } - public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + @objc public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return sections[section].count } - public func scrollViewDidScroll(_ scrollView: UIScrollView) { + @objc public func scrollViewDidScroll(_ scrollView: UIScrollView) { // In case the view is scrolled, dismiss the feedback window immediately // and reset the `progressBar` back to a full progress. abortAutodismiss() @@ -259,7 +271,7 @@ extension FeedbackViewController: UICollectionViewDataSource { } extension FeedbackViewController: UICollectionViewDelegate { - public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + @objc public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { abortAutodismiss() let item = sections[indexPath.section][indexPath.row] sendFeedbackHandler?(item) @@ -267,7 +279,7 @@ extension FeedbackViewController: UICollectionViewDelegate { } extension FeedbackViewController: UICollectionViewDelegateFlowLayout { - public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { + @objc public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { let availableWidth = collectionView.bounds.width // 3 columns and 2 rows in portrait mode. // 6 columns and 1 row in landscape mode. From 0801b8ba7c4b0e82c1c694b38527cf4d8a9775c5 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Wed, 22 Aug 2018 09:57:40 -0700 Subject: [PATCH 09/15] Make more public, use one section, doc --- MapboxNavigation/FeedbackItem.swift | 8 ++++- MapboxNavigation/FeedbackViewController.swift | 36 ++++++++----------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/MapboxNavigation/FeedbackItem.swift b/MapboxNavigation/FeedbackItem.swift index 977a534e24..ec6d45dbf6 100644 --- a/MapboxNavigation/FeedbackItem.swift +++ b/MapboxNavigation/FeedbackItem.swift @@ -7,13 +7,19 @@ extension UIImage { } } +/** + A single feedback item displayed on an instance of `FeedbackViewController`. + */ @objc(MBFeedbackItem) public class FeedbackItem: NSObject { var title: String var image: UIImage var feedbackType: FeedbackType - init(title: String, image: UIImage, feedbackType: FeedbackType) { + /** + Creates a new `FeedbackItem`. + */ + public init(title: String, image: UIImage, feedbackType: FeedbackType) { self.title = title self.image = image self.feedbackType = feedbackType diff --git a/MapboxNavigation/FeedbackViewController.swift b/MapboxNavigation/FeedbackViewController.swift index 21f693f84e..351cdd00ce 100644 --- a/MapboxNavigation/FeedbackViewController.swift +++ b/MapboxNavigation/FeedbackViewController.swift @@ -37,7 +37,7 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu /** The feedback items that are visible and selectable by the user. */ - public var sections: [[FeedbackItem]] = [[.turnNotAllowed, .closure, .reportTraffic, .confusingInstructions, .generalMapError, .badRoute]] + public var sections: [FeedbackItem] = [.turnNotAllowed, .closure, .reportTraffic, .confusingInstructions, .generalMapError, .badRoute] lazy var collectionView: UICollectionView = { let view: UICollectionView = UICollectionView(frame: .zero, collectionViewLayout: flowLayout) @@ -75,7 +75,10 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu return fullHeight } - var eventsManager: EventsManager + /** + The events manager used to send feedback events. + */ + public var eventsManager: EventsManager /** Initialize a new FeedbackViewController from an `EventsManager`. @@ -111,9 +114,9 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu progressBar.barColor = #colorLiteral(red: 0.9347146749, green: 0.5047877431, blue: 0.1419634521, alpha: 1) enableDraggableDismiss() - let defaults = defaultFeedbackHandlers() //this is done every time to refresh the feedback UUID - sendFeedbackHandler = defaults.send - dismissFeedbackHandler = defaults.dismiss + let uuid = eventsManager.recordFeedback() + sendFeedbackHandler = defaultSendFeedbackHandler(uuid: uuid) + dismissFeedbackHandler = defaultDismissFeedbackHandler(uuid: uuid) } override public func viewWillAppear(_ animated: Bool) { @@ -203,14 +206,6 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu progressBar.bottomAnchor.constraint(equalTo: view.safeBottomAnchor).isActive = true } - func defaultFeedbackHandlers(source: FeedbackSource = .user) -> (send: (FeedbackItem) -> Void, dismiss: () -> Void) { - let uuid = eventsManager.recordFeedback() - let send = defaultSendFeedbackHandler(uuid: uuid) - let dismiss = defaultDismissFeedbackHandler(uuid: uuid) - - return (send, dismiss) - } - func defaultSendFeedbackHandler(source: FeedbackSource = .user, uuid: UUID) -> (FeedbackItem) -> Void { return { [weak self] (item) in guard let strongSelf = self else { return } @@ -245,7 +240,7 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu extension FeedbackViewController: UICollectionViewDataSource { @objc public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: FeedbackCollectionViewCell.defaultIdentifier, for: indexPath) as! FeedbackCollectionViewCell - let item = sections[indexPath.section][indexPath.row] + let item = sections[indexPath.row] cell.titleLabel.text = item.title cell.imageView.tintColor = .clear @@ -255,11 +250,11 @@ extension FeedbackViewController: UICollectionViewDataSource { } @objc public func numberOfSections(in collectionView: UICollectionView) -> Int { - return sections.count + return 1 } @objc public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return sections[section].count + return sections.count } @objc public func scrollViewDidScroll(_ scrollView: UIScrollView) { @@ -273,7 +268,7 @@ extension FeedbackViewController: UICollectionViewDataSource { extension FeedbackViewController: UICollectionViewDelegate { @objc public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { abortAutodismiss() - let item = sections[indexPath.section][indexPath.row] + let item = sections[indexPath.row] sendFeedbackHandler?(item) } } @@ -283,11 +278,10 @@ extension FeedbackViewController: UICollectionViewDelegateFlowLayout { let availableWidth = collectionView.bounds.width // 3 columns and 2 rows in portrait mode. // 6 columns and 1 row in landscape mode. - let items = sections[indexPath.section] let width = traitCollection.verticalSizeClass == .compact - ? floor(availableWidth / CGFloat(items.count)) - : floor(availableWidth / CGFloat(items.count / 2)) - let item = sections[indexPath.section][indexPath.row] + ? floor(availableWidth / CGFloat(sections.count)) + : floor(availableWidth / CGFloat(sections.count / 2)) + let item = sections[indexPath.row] let titleHeight = item.title.height(constrainedTo: width, font: FeedbackCollectionViewCell.Constants.titleFont) let cellHeight: CGFloat = FeedbackCollectionViewCell.Constants.imageSize.height + FeedbackCollectionViewCell.Constants.padding From 0d465ed2a05ad35e1aaa2a562417d1e852981161 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Thu, 23 Aug 2018 09:07:17 -0700 Subject: [PATCH 10/15] Add delegate, make public, remove piping --- MapboxNavigation/FeedbackItem.swift | 19 ++++- MapboxNavigation/FeedbackViewController.swift | 80 +++++++++++-------- .../NavigationViewController.swift | 32 -------- MapboxNavigation/RouteMapViewController.swift | 5 -- 4 files changed, 61 insertions(+), 75 deletions(-) diff --git a/MapboxNavigation/FeedbackItem.swift b/MapboxNavigation/FeedbackItem.swift index ec6d45dbf6..107b8a81d0 100644 --- a/MapboxNavigation/FeedbackItem.swift +++ b/MapboxNavigation/FeedbackItem.swift @@ -12,14 +12,25 @@ extension UIImage { */ @objc(MBFeedbackItem) public class FeedbackItem: NSObject { - var title: String - var image: UIImage - var feedbackType: FeedbackType + /** + The title of feedback item. This will be rendered directly below the image. + */ + @objc public var title: String + + /** + An image representation of the feedback. + */ + @objc public var image: UIImage + + /** + The type of feedback that best describes the event. + */ + @objc public var feedbackType: FeedbackType /** Creates a new `FeedbackItem`. */ - public init(title: String, image: UIImage, feedbackType: FeedbackType) { + @objc public init(title: String, image: UIImage, feedbackType: FeedbackType) { self.title = title self.image = image self.feedbackType = feedbackType diff --git a/MapboxNavigation/FeedbackViewController.swift b/MapboxNavigation/FeedbackViewController.swift index 351cdd00ce..bd73fc869e 100644 --- a/MapboxNavigation/FeedbackViewController.swift +++ b/MapboxNavigation/FeedbackViewController.swift @@ -17,14 +17,32 @@ extension FeedbackViewController: UIViewControllerTransitioningDelegate { } } +/** + The `FeedbackViewControllerDelegate` protocol provides methods for responding to feedback events. + */ +@objc public protocol FeedbackViewControllerDelegate { + + /** + Called when the user opens the feedback form. + */ + @objc optional func feedbackViewControllerDidOpenFeedback(_ feedbackViewController: FeedbackViewController) + + /** + Called when the user submits a feedback event. + */ + @objc optional func feedbackViewController(_ feedbackViewController: FeedbackViewController, didSendFeedbackAssigned: UUID, feedback: FeedbackItem) + + /** + Called when a `FeedbackViewController` is dismissed for any reason without giving explicit feedback. + */ + @objc optional func feedbackViewControllerDidCancelFeedback(_ feedbackViewController: FeedbackViewController) +} + /** A view controller containing a grid of buttons the user can use to denote an issue their current navigation experience. */ @objc(MBFeedbackViewController) public class FeedbackViewController: UIViewController, DismissDraggable, UIGestureRecognizerDelegate { - - var sendFeedbackHandler: ((FeedbackItem) -> Void)? - var dismissFeedbackHandler: (() -> Void)? var activeFeedbackItem: FeedbackItem? static let sceneTitle = NSLocalizedString("FEEDBACK_TITLE", value: "Report Problem", comment: "Title of view controller for sending feedback") @@ -39,6 +57,8 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu */ public var sections: [FeedbackItem] = [.turnNotAllowed, .closure, .reportTraffic, .confusingInstructions, .generalMapError, .badRoute] + public var delegate: FeedbackViewControllerDelegate? + lazy var collectionView: UICollectionView = { let view: UICollectionView = UICollectionView(frame: .zero, collectionViewLayout: flowLayout) view.translatesAutoresizingMaskIntoConstraints = false @@ -80,6 +100,10 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu */ public var eventsManager: EventsManager + var uuid: UUID { + return eventsManager.recordFeedback() + } + /** Initialize a new FeedbackViewController from an `EventsManager`. */ @@ -113,10 +137,6 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu view.backgroundColor = .white progressBar.barColor = #colorLiteral(red: 0.9347146749, green: 0.5047877431, blue: 0.1419634521, alpha: 1) enableDraggableDismiss() - - let uuid = eventsManager.recordFeedback() - sendFeedbackHandler = defaultSendFeedbackHandler(uuid: uuid) - dismissFeedbackHandler = defaultDismissFeedbackHandler(uuid: uuid) } override public func viewWillAppear(_ animated: Bool) { @@ -127,6 +147,8 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu override public func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) + delegate?.feedbackViewControllerDidOpenFeedback?(self) + UIView.animate(withDuration: FeedbackViewController.autoDismissInterval) { self.progressBar.progress = 0 } @@ -168,7 +190,7 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu */ @objc public func dismissFeedback() { abortAutodismiss() - dismissFeedbackHandler?() + defaultDismissFeedback() } public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool { @@ -206,34 +228,24 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu progressBar.bottomAnchor.constraint(equalTo: view.safeBottomAnchor).isActive = true } - func defaultSendFeedbackHandler(source: FeedbackSource = .user, uuid: UUID) -> (FeedbackItem) -> Void { - return { [weak self] (item) in - guard let strongSelf = self else { return } - - // todo, can this be moved as a delegate on this view controller? - //strongSelf.delegate?.mapViewController(strongSelf, didSendFeedbackAssigned: uuid, feedbackType: item.feedbackType) - strongSelf.eventsManager.updateFeedback(uuid: uuid, type: item.feedbackType, source: source, description: nil) - - guard let parent = strongSelf.presentingViewController else { - strongSelf.dismiss(animated: true) - return - } - - strongSelf.dismiss(animated: true) { - DialogViewController().present(on: parent) - } + func sendFeedback(_ item: FeedbackItem) { + delegate?.feedbackViewController?(self, didSendFeedbackAssigned: uuid, feedback: item) + eventsManager.updateFeedback(uuid: uuid, type: item.feedbackType, source: .user, description: nil) + + guard let parent = presentingViewController else { + dismiss(animated: true) + return + } + + dismiss(animated: true) { + DialogViewController().present(on: parent) } } - func defaultDismissFeedbackHandler(uuid: UUID) -> (() -> Void) { - return { [weak self ] in - guard let strongSelf = self else { return } - - // todo, can this be moved as a delegate on this view controller? - // strongSelf.delegate?.mapViewControllerDidCancelFeedback(strongSelf) - strongSelf.eventsManager.cancelFeedback(uuid: uuid) - strongSelf.dismiss(animated: true, completion: nil) - } + func defaultDismissFeedback() { + delegate?.feedbackViewControllerDidCancelFeedback?(self) + eventsManager.cancelFeedback(uuid: uuid) + dismiss(animated: true, completion: nil) } } @@ -269,7 +281,7 @@ extension FeedbackViewController: UICollectionViewDelegate { @objc public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { abortAutodismiss() let item = sections[indexPath.row] - sendFeedbackHandler?(item) + sendFeedback(item) } } diff --git a/MapboxNavigation/NavigationViewController.swift b/MapboxNavigation/NavigationViewController.swift index 18fba30b2c..e03ea9e8aa 100644 --- a/MapboxNavigation/NavigationViewController.swift +++ b/MapboxNavigation/NavigationViewController.swift @@ -150,26 +150,6 @@ public protocol NavigationViewControllerDelegate: VisualInstructionDelegate { @objc(navigationViewController:viewForAnnotation:) optional func navigationViewController(_ navigationViewController: NavigationViewController, viewFor annotation: MGLAnnotation) -> MGLAnnotationView? - /** - Called when the user opens the feedback form. - */ - @objc optional func navigationViewControllerDidOpenFeedback(_ viewController: NavigationViewController) - - /** - Called when the user dismisses the feedback form. - */ - @objc optional func navigationViewControllerDidCancelFeedback(_ viewController: NavigationViewController) - - /** - Called when the user sends feedback. - - - parameter viewController: The navigation view controller that reported the feedback. - - parameter uuid: The feedback event’s unique identifier. - - parameter feedbackType: The type of feedback event that was sent. - */ - @objc(navigationViewController:didSendFeedbackAssignedUUID:feedbackType:) - optional func navigationViewController(_ viewController: NavigationViewController, didSendFeedbackAssigned uuid: UUID, feedbackType: FeedbackType) - /** Returns the center point of the user course view in screen coordinates relative to the map view. */ @@ -525,14 +505,6 @@ extension NavigationViewController: RouteMapViewControllerDelegate { return delegate?.navigationViewController?(self, viewFor: annotation) } - func mapViewControllerDidOpenFeedback(_ mapViewController: RouteMapViewController) { - delegate?.navigationViewControllerDidOpenFeedback?(self) - } - - func mapViewControllerDidCancelFeedback(_ mapViewController: RouteMapViewController) { - delegate?.navigationViewControllerDidCancelFeedback?(self) - } - func mapViewControllerDidDismiss(_ mapViewController: RouteMapViewController, byCanceling canceled: Bool) { if delegate?.navigationViewControllerDidDismiss?(self, byCanceling: canceled) != nil { // The receiver should handle dismissal of the NavigationViewController @@ -541,10 +513,6 @@ extension NavigationViewController: RouteMapViewControllerDelegate { } } - func mapViewController(_ mapViewController: RouteMapViewController, didSendFeedbackAssigned uuid: UUID, feedbackType: FeedbackType) { - delegate?.navigationViewController?(self, didSendFeedbackAssigned: uuid, feedbackType: feedbackType) - } - public func navigationMapViewUserAnchorPoint(_ mapView: NavigationMapView) -> CGPoint { return delegate?.navigationViewController?(self, mapViewUserAnchorPoint: mapView) ?? .zero } diff --git a/MapboxNavigation/RouteMapViewController.swift b/MapboxNavigation/RouteMapViewController.swift index 609307051c..b59591a074 100644 --- a/MapboxNavigation/RouteMapViewController.swift +++ b/MapboxNavigation/RouteMapViewController.swift @@ -240,7 +240,6 @@ class RouteMapViewController: UIViewController { @objc func feedback(_ sender: Any) { showFeedback() - delegate?.mapViewControllerDidOpenFeedback(self) } func showFeedback(source: FeedbackSource = .user) { @@ -988,11 +987,7 @@ fileprivate extension UIViewAnimationOptions { } } @objc protocol RouteMapViewControllerDelegate: NavigationMapViewDelegate, MGLMapViewDelegate, VisualInstructionDelegate { - - func mapViewControllerDidOpenFeedback(_ mapViewController: RouteMapViewController) - func mapViewControllerDidCancelFeedback(_ mapViewController: RouteMapViewController) func mapViewControllerDidDismiss(_ mapViewController: RouteMapViewController, byCanceling canceled: Bool) - func mapViewController(_ mapViewController: RouteMapViewController, didSendFeedbackAssigned uuid: UUID, feedbackType: FeedbackType) func mapViewControllerShouldAnnotateSpokenInstructions(_ routeMapViewController: RouteMapViewController) -> Bool /** From 4f56aeda77bafbeb9ea42419c7ded1e32469e427 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Thu, 23 Aug 2018 09:42:15 -0700 Subject: [PATCH 11/15] weak --- MapboxNavigation/FeedbackViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MapboxNavigation/FeedbackViewController.swift b/MapboxNavigation/FeedbackViewController.swift index bd73fc869e..f73208ddac 100644 --- a/MapboxNavigation/FeedbackViewController.swift +++ b/MapboxNavigation/FeedbackViewController.swift @@ -57,7 +57,7 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu */ public var sections: [FeedbackItem] = [.turnNotAllowed, .closure, .reportTraffic, .confusingInstructions, .generalMapError, .badRoute] - public var delegate: FeedbackViewControllerDelegate? + @objc public weak var delegate: FeedbackViewControllerDelegate? lazy var collectionView: UICollectionView = { let view: UICollectionView = UICollectionView(frame: .zero, collectionViewLayout: flowLayout) From 72e3740c42f0c4889c17467ed6cf8e6b76bd8751 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Thu, 23 Aug 2018 11:14:25 -0700 Subject: [PATCH 12/15] Update names --- MapboxNavigation/FeedbackViewController.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/MapboxNavigation/FeedbackViewController.swift b/MapboxNavigation/FeedbackViewController.swift index f73208ddac..f362ac4120 100644 --- a/MapboxNavigation/FeedbackViewController.swift +++ b/MapboxNavigation/FeedbackViewController.swift @@ -25,12 +25,12 @@ extension FeedbackViewController: UIViewControllerTransitioningDelegate { /** Called when the user opens the feedback form. */ - @objc optional func feedbackViewControllerDidOpenFeedback(_ feedbackViewController: FeedbackViewController) + @objc optional func feedbackViewControllerDidOpen(_ feedbackViewController: FeedbackViewController) /** Called when the user submits a feedback event. */ - @objc optional func feedbackViewController(_ feedbackViewController: FeedbackViewController, didSendFeedbackAssigned: UUID, feedback: FeedbackItem) + @objc optional func feedbackViewController(_ feedbackViewController: FeedbackViewController, didSend: FeedbackItem, UUID: UUID) /** Called when a `FeedbackViewController` is dismissed for any reason without giving explicit feedback. @@ -147,7 +147,7 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu override public func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) - delegate?.feedbackViewControllerDidOpenFeedback?(self) + delegate?.feedbackViewControllerDidOpen?(self) UIView.animate(withDuration: FeedbackViewController.autoDismissInterval) { self.progressBar.progress = 0 @@ -190,7 +190,7 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu */ @objc public func dismissFeedback() { abortAutodismiss() - defaultDismissFeedback() + dismissFeedbackItem() } public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool { @@ -228,8 +228,8 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu progressBar.bottomAnchor.constraint(equalTo: view.safeBottomAnchor).isActive = true } - func sendFeedback(_ item: FeedbackItem) { - delegate?.feedbackViewController?(self, didSendFeedbackAssigned: uuid, feedback: item) + func send(_ item: FeedbackItem) { + delegate?.feedbackViewController?(self, didSend: item, UUID: uuid) eventsManager.updateFeedback(uuid: uuid, type: item.feedbackType, source: .user, description: nil) guard let parent = presentingViewController else { @@ -242,7 +242,7 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu } } - func defaultDismissFeedback() { + func dismissFeedbackItem() { delegate?.feedbackViewControllerDidCancelFeedback?(self) eventsManager.cancelFeedback(uuid: uuid) dismiss(animated: true, completion: nil) @@ -281,7 +281,7 @@ extension FeedbackViewController: UICollectionViewDelegate { @objc public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { abortAutodismiss() let item = sections[indexPath.row] - sendFeedback(item) + send(item) } } From eaa640a81ab169baca27c4a1dce68d12479301ff Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Thu, 23 Aug 2018 11:18:21 -0700 Subject: [PATCH 13/15] Let Style class define color --- MapboxNavigation/FeedbackViewController.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/MapboxNavigation/FeedbackViewController.swift b/MapboxNavigation/FeedbackViewController.swift index f362ac4120..68bbde3ea6 100644 --- a/MapboxNavigation/FeedbackViewController.swift +++ b/MapboxNavigation/FeedbackViewController.swift @@ -135,7 +135,6 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu view.layoutIfNeeded() transitioningDelegate = self view.backgroundColor = .white - progressBar.barColor = #colorLiteral(red: 0.9347146749, green: 0.5047877431, blue: 0.1419634521, alpha: 1) enableDraggableDismiss() } From 41bf3ac0d8c12de94a79348310ae5b373f155c30 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Thu, 23 Aug 2018 13:49:21 -0700 Subject: [PATCH 14/15] Change names --- MapboxNavigation/FeedbackViewController.swift | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/MapboxNavigation/FeedbackViewController.swift b/MapboxNavigation/FeedbackViewController.swift index 68bbde3ea6..9c74732cb8 100644 --- a/MapboxNavigation/FeedbackViewController.swift +++ b/MapboxNavigation/FeedbackViewController.swift @@ -30,12 +30,13 @@ extension FeedbackViewController: UIViewControllerTransitioningDelegate { /** Called when the user submits a feedback event. */ - @objc optional func feedbackViewController(_ feedbackViewController: FeedbackViewController, didSend: FeedbackItem, UUID: UUID) + @objc(feedbackViewController:didSendFeedbackItem:UUID:) + optional func feedbackViewController(_ feedbackViewController: FeedbackViewController, didSend feedbackItem: FeedbackItem, uuid: UUID) /** Called when a `FeedbackViewController` is dismissed for any reason without giving explicit feedback. */ - @objc optional func feedbackViewControllerDidCancelFeedback(_ feedbackViewController: FeedbackViewController) + @objc optional func feedbackViewControllerDidCancel(_ feedbackViewController: FeedbackViewController) } /** @@ -228,7 +229,7 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu } func send(_ item: FeedbackItem) { - delegate?.feedbackViewController?(self, didSend: item, UUID: uuid) + delegate?.feedbackViewController?(self, didSend: item, uuid: uuid) eventsManager.updateFeedback(uuid: uuid, type: item.feedbackType, source: .user, description: nil) guard let parent = presentingViewController else { @@ -242,7 +243,7 @@ public class FeedbackViewController: UIViewController, DismissDraggable, UIGestu } func dismissFeedbackItem() { - delegate?.feedbackViewControllerDidCancelFeedback?(self) + delegate?.feedbackViewControllerDidCancel?(self) eventsManager.cancelFeedback(uuid: uuid) dismiss(animated: true, completion: nil) } From 7ccfa2d922ed38c41a6f62df8338cdddad7d3ac5 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Thu, 23 Aug 2018 14:06:26 -0700 Subject: [PATCH 15/15] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc493d16ad..809c9e75b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * Made functions on `StatusView` public allowing for better interaction. [#1612](https://github.com/mapbox/mapbox-navigation-ios/pull/1612) * Added a `MapboxVoiceController.audioPlayer` property. You can use this property to interrupt a spoken instruction or adjust the volume. [#1596](https://github.com/mapbox/mapbox-navigation-ios/pull/1596) * Added `StyleManager.automaticallyAdjustsStyleForTimeOfDay`, `StyleManager.delegate`, and `StyleManager.styles` properties so that you can control same time-based style switching just as NavigationViewController does. [#1617](https://github.com/mapbox/mapbox-navigation-ios/pull/1617) +* `FeedbackViewController` is now public making it possible to add the feedback view to a custom navigation UI. [#1605](https://github.com/mapbox/mapbox-navigation-ios/pull/1605/). `navigationViewControllerDidOpenFeedback(_:)`, `navigationViewControllerDidCancelFeedback(_:)` and `navigationViewController(_:uuid:feedbackType)` have all been moved to `FeedbackViewControllerDelegate`. ## v0.19.1 (August 15, 2018)