-
Notifications
You must be signed in to change notification settings - Fork 62
Enable or disable the “Add Sensors” button #60
base: master
Are you sure you want to change the base?
Enable or disable the “Add Sensors” button #60
Conversation
Based on whether there are unused sensors available for the device.
@@ -429,6 +429,12 @@ extension ActionArea { | |||
(stackView.arrangedSubviews.count ..< 4).forEach { _ in | |||
stackView.addArrangedSubview(UIView()) | |||
} | |||
|
|||
items.forEach { (item) in |
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.
no parens around block args (item
and enabled
)
items.forEach { (item) in | ||
item.enabler?.observe({ (enabled) in | ||
self.setButtonFor(item: item, enabled: enabled) | ||
}) |
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.
Do all the items need to be re-enabled here? It seems like if one were previously disabled, it may not get turned back on after a button change.
button.isEnabled = enabled | ||
let updatedAlpha: CGFloat = enabled ? 1.0 : BarViewController.Metrics.Bar.disabledAlpha | ||
if animated { | ||
UIView.animate(withDuration: 0.5) { |
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'd move the animation block up to the VC. It currently controls timings for animations, so it'll be easier to reason about with those in the same place. There's also some logic up there related to enabling/disabling the entire bar/detail era, and the alpha values there and here are likely related.
@@ -176,6 +176,8 @@ open class ObserveViewController: ScienceJournalCollectionViewController, ChartC | |||
return self.observeDataSource.availableSensorIDs | |||
} | |||
|
|||
@objc dynamic private(set) var unusedSensors: Bool = false |
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.
hasUnusedSensors
would be more consistent with the property naming guidelines for boolean values.
Checklist
Motivation and Context
The "Add Sensor" button in the action area remains enabled, even when there are no additional sensors to add. This could be confusing for users. The visual characteristics and interactivity of the "Add Sensor" button should change based on whether there are unused sensors available for the device.
Description
unusedSensors
Bool
toObserveViewController
to store the current state of sensors that are available but not currently in use.enabler
property toBarButtonItem
to handle KVO observations ofBool
properties.enabler
for the "Add Sensor" bar button item, to observe changes toObserveViewController
'sunusedSensors
property.setButtonFor(item:enabled:animated:)
method to theActionArea.Bar
to toggle enabled for buttons based on observations received by aBarButtonItem
.setEnabled(_:animated:)
method on theBarButton
to change the interactivity and alpha of its subviews.Tested in the simulator and on devices running iOS 12 and 13.