-
Notifications
You must be signed in to change notification settings - Fork 318
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
Allow the use of multiple status banners #2747
Merged
jill-cardamon
merged 40 commits into
main
from
jill-enable-precise-location-tailwork-2723
Mar 11, 2021
Merged
Changes from 37 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
008c70e
created struct to represent showStatus, refactored relevant files, st…
2c91aa9
statuses append correctly and don't duplicate, continued work on show…
ff37fac
added show and hide to manageStatuses() method
f2ff5df
refactored rerouting status and broke array appending
8cb1376
refactor to have all logic for status banner management within Status…
3aac0ee
update integration test fixture
3e7f2dd
expose hideStatus(status:) to NavigationViewController and TopBannerV…
eb9600c
hiding enable precise location status is triggered automatically but …
a8a2020
issue with showing other statuses after one is hiddin is that there a…
28d0b16
shows and hides multiple status banners properly; enable precise loca…
d46a345
need to add another way to hide to handle the case where things don't…
60b02d7
reflect added test file
7be66f1
change how status is hidden in manageStatuses()
67ebac9
add delay to hideStatus() call within manageStatuses(), change enable…
beeee42
changed name of authorizationChange boolean for clarity
739d32e
deleted all calls/mentions of showStatus()
98b9730
clean up code, add more test cases
d9af246
test cases pass as expected
c77e74a
made test cases more resiliant; need to investigate using hideStatus(…
c77e3f6
trying to use dispatch queue in hide
eee4c9f
contained all delays within hide(), doesn't work
d989ead
works with only one dispatch queue, need to rerun tests
6cad500
deprecated old showStatus method, tests are better written and all bu…
81f30c2
updated test cases, wait for expectation fails but it's supposed to s…
1b73921
fixed failing test, removed debugging statements, clean up code
1b0d4e0
incorporating feedback
069922c
made priority public, added inline doc for addNewStatus()
53cd613
update changelog, clean up code, add reducedAccuracyActivatedMode == …
d6c4bcf
MapboxNavigationNative v31.0.1
1ec5 8790a4c
Add Changelog entry.
avi-c a673fe2
Fix CHANGELOG entry to mention CarPlay
avi-c 5e41168
Typo
1ec5 b519916
update changelog, clean up code, add reducedAccuracyActivatedMode == …
057974e
incorporated feedback, update changelog
d948241
remove unnecessary doc comments from previous commit
7847b34
fix changelog issue
515dab5
fix status initialization in StatusViewTests
8c5719d
switch to typealias being priority instead of rawrepresentable
572b1b1
add doc comments, fix naming for priority value
fdd9ca6
clean up doc comments, remove Priority struct entirely
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,39 @@ public class StatusView: UIControl { | |
} | ||
} | ||
|
||
var statuses: [Status] = [] | ||
|
||
/** | ||
`Status` is a struct which stores information to be displayed by the `StatusView` | ||
*/ | ||
public struct Status { | ||
public var identifier: String | ||
let title: String | ||
var spinner: Bool = false | ||
let duration: TimeInterval | ||
var animated: Bool = true | ||
var interactive: Bool = false | ||
var priority: Priority | ||
1ec5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
`Priority` is used to display `Status`es by importance | ||
*/ | ||
public struct Priority: RawRepresentable { | ||
public typealias RawValue = Int | ||
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. Since no specific values are defined, it would be simpler to define a type alias than a raw representable type alias inside a struct:
|
||
|
||
public var rawValue: Int | ||
|
||
public init(rawValue: Int) { | ||
self.rawValue = rawValue | ||
} | ||
// — Highest Priority — | ||
// rerouting (rawValue = 0) | ||
// enable precise location (rawValue = 1) | ||
// simulation banner (rawValue = 2) | ||
// — Lowest Priority — | ||
1ec5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
public override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
commonInit() | ||
|
@@ -84,6 +117,7 @@ public class StatusView: UIControl { | |
|
||
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(StatusView.tap(_:))) | ||
addGestureRecognizer(tapRecognizer) | ||
|
||
} | ||
|
||
@objc func pan(_ sender: UIPanGestureRecognizer) { | ||
|
@@ -117,62 +151,111 @@ public class StatusView: UIControl { | |
} | ||
} | ||
|
||
/** | ||
Shows the status view for a specified amount of time. | ||
`showStatus()` uses a default value for priority and the title input as identifier. To use these variables, use `show(_:)` | ||
*/ | ||
@available(*, deprecated, message: "Add a status using show(_:) instead") | ||
public func showStatus(title: String, spinner spin: Bool = false, duration: TimeInterval, animated: Bool = true, interactive: Bool = false) { | ||
show(title, showSpinner: spin, interactive: interactive) | ||
guard duration < .infinity else { return } | ||
hide(delay: duration, animated: animated) | ||
let status = Status(identifier: title, title: title, spinner: spin, duration: duration, animated: animated, interactive: interactive, priority: StatusView.Priority(rawValue: 1)) | ||
show(status) | ||
} | ||
|
||
/** | ||
Adds a new status to statuses array. | ||
*/ | ||
func show(_ status: Status) { | ||
if let row = statuses.firstIndex(where: {$0.identifier.contains(status.identifier)}) { | ||
statuses[row] = status | ||
} else { | ||
statuses.append(status) | ||
} | ||
manageStatuses() | ||
} | ||
|
||
/** | ||
Manages showing and hiding Statuses and the status view itself. | ||
*/ | ||
func manageStatuses(status: Status? = nil) { | ||
if statuses.isEmpty { | ||
hide(delay: status?.duration ?? 0, animated: status?.animated ?? true) | ||
} else { | ||
// if we hide a Status and there are Statuses left in the statuses array, show the Status with highest priority | ||
guard let highestPriorityStatus = statuses.min(by: {$0.priority.rawValue < $1.priority.rawValue}) else { return } | ||
show(status: highestPriorityStatus) | ||
hide(with: highestPriorityStatus, delay: highestPriorityStatus.duration) | ||
} | ||
} | ||
|
||
/** | ||
Hides a given Status without hiding the status view. | ||
*/ | ||
func hide(_ status: Status?) { | ||
guard let identifier = status?.identifier else { return } | ||
guard let row = statuses.firstIndex(where: {$0.identifier.contains(identifier)}) else { return } | ||
1ec5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let removedStatus = statuses.remove(at: row) | ||
manageStatuses(status: removedStatus) | ||
} | ||
|
||
func showSimulationStatus(speed: Int) { | ||
let format = NSLocalizedString("USER_IN_SIMULATION_MODE", bundle: .mapboxNavigation, value: "Simulating Navigation at %@×", comment: "The text of a banner that appears during turn-by-turn navigation when route simulation is enabled.") | ||
let title = String.localizedStringWithFormat(format, NumberFormatter.localizedString(from: speed as NSNumber, number: .decimal)) | ||
showStatus(title: title, duration: .infinity, interactive: true) | ||
let simulationStatus = Status(identifier: "USER_IN_SIMULATION_MODE", title: title, duration: .infinity, interactive: true, priority: StatusView.Priority(rawValue: 2)) | ||
show(simulationStatus) | ||
} | ||
|
||
/** | ||
Shows the status view with an optional spinner. | ||
*/ | ||
public func show(_ title: String, showSpinner: Bool, interactive: Bool = false) { | ||
isEnabled = interactive | ||
textLabel.text = title | ||
public func show(status: Status) { | ||
isEnabled = status.interactive | ||
textLabel.text = status.title | ||
activityIndicatorView.hidesWhenStopped = true | ||
if (!showSpinner) { activityIndicatorView.stopAnimating() } | ||
if (!status.spinner) { activityIndicatorView.stopAnimating() } | ||
|
||
guard !isCurrentlyVisible, isHidden else { return } | ||
|
||
let show = { | ||
self.isHidden = false | ||
self.textLabel.alpha = 1 | ||
if (showSpinner) { self.activityIndicatorView.isHidden = false } | ||
if (status.spinner) { self.activityIndicatorView.isHidden = false } | ||
self.superview?.layoutIfNeeded() | ||
} | ||
|
||
UIView.defaultAnimation(0.3, animations:show, completion:{ _ in | ||
self.isCurrentlyVisible = true | ||
guard showSpinner else { return } | ||
guard status.spinner else { return } | ||
self.activityIndicatorView.startAnimating() | ||
}) | ||
} | ||
|
||
/** | ||
Hides the status view. | ||
*/ | ||
public func hide(delay: TimeInterval = 0, animated: Bool = true) { | ||
public func hide(with status: Status? = nil, delay: TimeInterval = 0, animated: Bool = true) { | ||
let hide = { | ||
self.isHidden = true | ||
self.textLabel.alpha = 0 | ||
self.activityIndicatorView.isHidden = true | ||
if status == nil { | ||
self.isHidden = true | ||
self.textLabel.alpha = 0 | ||
self.activityIndicatorView.isHidden = true | ||
} else { | ||
self.hide(status) | ||
} | ||
} | ||
|
||
let animate = { | ||
let fireTime = DispatchTime.now() + delay | ||
DispatchQueue.main.asyncAfter(deadline: fireTime, execute: { | ||
guard !self.isHidden, self.isCurrentlyVisible else { return } | ||
|
||
self.activityIndicatorView.stopAnimating() | ||
UIView.defaultAnimation(0.3, delay: 0, animations: hide, completion: { _ in | ||
self.isCurrentlyVisible = false | ||
}) | ||
if status == nil { | ||
guard !self.isHidden, self.isCurrentlyVisible else { return } | ||
|
||
self.activityIndicatorView.stopAnimating() | ||
UIView.defaultAnimation(0.3, delay: 0, animations: hide, completion: { _ in | ||
self.isCurrentlyVisible = false | ||
}) | ||
} else { | ||
self.hide(status) | ||
} | ||
}) | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 change looks like a bad merge; can you revert it? Thanks!