Merge branch 'feature/store_heart_update' into 'develop'

update to make heart enableaable and optional

See merge request BPHV_MIPS/mvm_core_ui!637
This commit is contained in:
Pfeil, Scott Robert 2020-12-11 09:32:33 -05:00
commit 4dc6d59c2c
4 changed files with 42 additions and 16 deletions

View File

@ -79,8 +79,6 @@ import UIKit
heightConstraint = heightAnchor.constraint(equalTo: widthAnchor, multiplier: 1) heightConstraint = heightAnchor.constraint(equalTo: widthAnchor, multiplier: 1)
heightConstraint?.isActive = true heightConstraint?.isActive = true
isAccessibilityElement = true isAccessibilityElement = true
accessibilityTraits = .button
updateAccessibilityLabel()
} }
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
@ -89,6 +87,8 @@ import UIKit
self.additionalData = additionalData self.additionalData = additionalData
guard let model = model as? HeartModel else { return } guard let model = model as? HeartModel else { return }
isSelected = model.isActive isSelected = model.isActive
isEnabled = model.enabled
updateAccessibilityLabel()
} }
//-------------------------------------------------- //--------------------------------------------------
@ -96,11 +96,13 @@ import UIKit
//-------------------------------------------------- //--------------------------------------------------
/// Adjust accessibility label based on selection of Heart. /// Adjust accessibility label based on selection of Heart.
func updateAccessibilityLabel() { func updateAccessibilityLabel() {
accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: isSelected ? "heart_unfavorite_action_hint" : "heart_favorite_action_hint") accessibilityHint = isEnabled ? MVMCoreUIUtility.hardcodedString(withKey: isSelected ? "heart_unfavorite_action_hint" : "heart_favorite_action_hint") : nil
accessibilityTraits = isEnabled ? .button : .none
accessibilityLabel = MVMCoreUIUtility.hardcodedString(withKey: isSelected ? "heart_selected_state" : "heart_not_selected_state") accessibilityLabel = MVMCoreUIUtility.hardcodedString(withKey: isSelected ? "heart_selected_state" : "heart_not_selected_state")
} }
func tapAction() { func tapAction() {
guard isEnabled else { return }
isSelected = !isSelected isSelected = !isSelected
if let heartModel = heartModel { if let heartModel = heartModel {
Button.performButtonAction(with: heartModel.action, button: self, delegateObject: delegateObject, additionalData: additionalData, sourceModel: heartModel) Button.performButtonAction(with: heartModel.action, button: self, delegateObject: delegateObject, additionalData: additionalData, sourceModel: heartModel)

View File

@ -8,7 +8,7 @@
import Foundation import Foundation
open class HeartModel: MoleculeModelProtocol { open class HeartModel: MoleculeModelProtocol, EnableableModelProtocol {
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Properties // MARK: - Properties
@ -19,6 +19,7 @@ open class HeartModel: MoleculeModelProtocol {
public var activeColor: Color = Color(uiColor: .mvmRed) public var activeColor: Color = Color(uiColor: .mvmRed)
public var inActiveColor: Color = Color(uiColor: .clear) public var inActiveColor: Color = Color(uiColor: .clear)
public var action: ActionModelProtocol = ActionNoopModel() public var action: ActionModelProtocol = ActionNoopModel()
public var enabled: Bool = true
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Keys // MARK: - Keys
@ -30,6 +31,7 @@ open class HeartModel: MoleculeModelProtocol {
case activeColor case activeColor
case inActiveColor case inActiveColor
case action case action
case enabled
} }
//-------------------------------------------------- //--------------------------------------------------
@ -51,6 +53,9 @@ open class HeartModel: MoleculeModelProtocol {
if let action: ActionModelProtocol = try typeContainer.decodeModelIfPresent(codingKey: .action) { if let action: ActionModelProtocol = try typeContainer.decodeModelIfPresent(codingKey: .action) {
self.action = action self.action = action
} }
if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) {
self.enabled = enabled
}
} }
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
@ -61,5 +66,6 @@ open class HeartModel: MoleculeModelProtocol {
try container.encode(activeColor, forKey: .activeColor) try container.encode(activeColor, forKey: .activeColor)
try container.encode(inActiveColor, forKey: .inActiveColor) try container.encode(inActiveColor, forKey: .inActiveColor)
try container.encodeModel(action, forKey: .action) try container.encodeModel(action, forKey: .action)
try container.encode(enabled, forKey: .enabled)
} }
} }

View File

@ -42,8 +42,6 @@
addMolecule(stack) addMolecule(stack)
stack.restack() stack.restack()
horizontalStack.restack() horizontalStack.restack()
accessibilityHint = heart.accessibilityHint
accessibilityTraits = heart.accessibilityTraits
} }
public override func updateView(_ size: CGFloat) { public override func updateView(_ size: CGFloat) {
@ -123,20 +121,40 @@
} }
func updateAccessibilityLabel() { func updateAccessibilityLabel() {
if let accessoryView = accessoryView { let hasHeart = !(horizontalStack.stackModel?.molecules[1].gone ?? true)
// Both caret and heart. if let accessoryView = accessoryView,
hasHeart {
// Both accessory and heart actions.
isAccessibilityElement = false isAccessibilityElement = false
accessoryView.accessibilityLabel = getAccessibilityMessage() accessoryView.accessibilityLabel = getAccessibilityMessage()
accessibilityElements = [accessoryView, heart] accessibilityElements = [accessoryView, heart]
} else { } else {
// Make whole cell focusable if no action. // Make whole cell focusable if no action.
isAccessibilityElement = true isAccessibilityElement = true
if let message = getAccessibilityMessage(), var message = getAccessibilityMessage()
let heartLabel = heart.accessibilityLabel { if hasHeart {
accessibilityLabel = message + ", " + heartLabel accessibilityHint = heart.accessibilityHint
if let heartLabel = heart.accessibilityLabel {
message = (message ?? "") + ", " + heartLabel
}
} else { } else {
accessibilityLabel = getAccessibilityMessage() accessibilityHint = nil
} }
accessibilityLabel = message
} }
} }
// Ensures voice over does not read "selected" after user triggers action on cell.
override public var accessibilityTraits: UIAccessibilityTraits {
get {
if (accessoryView != nil) {
return .button
} else if (!(horizontalStack.stackModel?.molecules[1].gone ?? true)) {
return heart.accessibilityTraits
} else {
return .none
}
}
set {}
}
} }

View File

@ -12,7 +12,7 @@ public class ListStoreLocatorModel: ListItemModel, MoleculeModelProtocol {
//-------------------------------------------------- //--------------------------------------------------
public static var identifier = "listStoreLocator" public static var identifier = "listStoreLocator"
public var heart: HeartModel public var heart: HeartModel?
public var leftHeadline: LabelModel public var leftHeadline: LabelModel
public var leftBody: LabelModel public var leftBody: LabelModel
public var leftSubBody: LabelModel public var leftSubBody: LabelModel
@ -22,7 +22,7 @@ public class ListStoreLocatorModel: ListItemModel, MoleculeModelProtocol {
// MARK: - Initializer // MARK: - Initializer
//-------------------------------------------------- //--------------------------------------------------
public init(heart: HeartModel, leftHeadline: LabelModel, leftBody: LabelModel, leftSubBody: LabelModel, rightLabel: LabelModel) { public init(heart: HeartModel?, leftHeadline: LabelModel, leftBody: LabelModel, leftSubBody: LabelModel, rightLabel: LabelModel) {
self.heart = heart self.heart = heart
self.leftHeadline = leftHeadline self.leftHeadline = leftHeadline
self.leftBody = leftBody self.leftBody = leftBody
@ -59,7 +59,7 @@ public class ListStoreLocatorModel: ListItemModel, MoleculeModelProtocol {
public required init(from decoder: Decoder) throws { public required init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
heart = try typeContainer.decode(HeartModel.self, forKey:.heart) heart = try typeContainer.decodeIfPresent(HeartModel.self, forKey:.heart)
leftHeadline = try typeContainer.decode(LabelModel.self, forKey: .leftHeadline) leftHeadline = try typeContainer.decode(LabelModel.self, forKey: .leftHeadline)
leftBody = try typeContainer.decode(LabelModel.self, forKey: .leftBody) leftBody = try typeContainer.decode(LabelModel.self, forKey: .leftBody)
leftSubBody = try typeContainer.decode(LabelModel.self, forKey: .leftSubBody) leftSubBody = try typeContainer.decode(LabelModel.self, forKey: .leftSubBody)
@ -71,7 +71,7 @@ public class ListStoreLocatorModel: ListItemModel, MoleculeModelProtocol {
try super.encode(to: encoder) try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(moleculeName, forKey: .moleculeName) try container.encode(moleculeName, forKey: .moleculeName)
try container.encode(heart, forKey: .heart) try container.encodeIfPresent(heart, forKey: .heart)
try container.encode(leftHeadline, forKey: .leftHeadline) try container.encode(leftHeadline, forKey: .leftHeadline)
try container.encode(leftBody, forKey: .leftBody) try container.encode(leftBody, forKey: .leftBody)
try container.encode(leftSubBody, forKey: .leftSubBody) try container.encode(leftSubBody, forKey: .leftSubBody)