Code fixes and added accessibility.
This commit is contained in:
parent
04bbf58e6a
commit
06df235fb2
@ -8,7 +8,8 @@
|
|||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
open class Heart: Control {
|
@objcMembers open class Heart: Control {
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -16,6 +17,7 @@ open class Heart: Control {
|
|||||||
@objc public override var isSelected: Bool {
|
@objc public override var isSelected: Bool {
|
||||||
didSet {
|
didSet {
|
||||||
heartModel?.isActive = isSelected
|
heartModel?.isActive = isSelected
|
||||||
|
updateAccessibilityLabel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public var delegateObject: MVMCoreUIDelegateObject?
|
public var delegateObject: MVMCoreUIDelegateObject?
|
||||||
@ -24,9 +26,15 @@ open class Heart: Control {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Lifecycle
|
// MARK: - Constraints
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
open override func draw(_ layer: CALayer, in ctx: CGContext) {
|
public var widthConstraint: NSLayoutConstraint?
|
||||||
|
public var heightConstraint: NSLayoutConstraint?
|
||||||
|
|
||||||
|
//------------------------------------------------------
|
||||||
|
// MARK: - State Handling
|
||||||
|
//------------------------------------------------------
|
||||||
|
open override func draw(_ rect: CGRect) {
|
||||||
//Draw the heart
|
//Draw the heart
|
||||||
heartLayer?.removeFromSuperlayer()
|
heartLayer?.removeFromSuperlayer()
|
||||||
let heart = drawHeart()
|
let heart = drawHeart()
|
||||||
@ -36,7 +44,7 @@ open class Heart: Control {
|
|||||||
|
|
||||||
func drawHeart() -> CAShapeLayer {
|
func drawHeart() -> CAShapeLayer {
|
||||||
let heart = CAShapeLayer()
|
let heart = CAShapeLayer()
|
||||||
let rect = CGRect(x: 0, y: 0, width: 22, height: 22)
|
let rect = CGRect(x: 0, y: 0, width: 10, height: 10)
|
||||||
let leftArc = rect.width * 0.4
|
let leftArc = rect.width * 0.4
|
||||||
let rightArc = rect.height * 0.3
|
let rightArc = rect.height * 0.3
|
||||||
let arcRadius = sqrt(leftArc*leftArc + rightArc*rightArc)/2
|
let arcRadius = sqrt(leftArc*leftArc + rightArc*rightArc)/2
|
||||||
@ -60,15 +68,19 @@ open class Heart: Control {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - MVMViewProtocol
|
// MARK: - Lifecycle
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
open override func setupView() {
|
open override func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
}
|
addTarget(self, action: #selector(tapAction), for: .touchUpInside)
|
||||||
|
widthConstraint = widthAnchor.constraint(equalToConstant: 10)
|
||||||
open override func updateView(_ size: CGFloat) {
|
widthConstraint?.isActive = true
|
||||||
super.updateView(size)
|
heightConstraint = heightAnchor.constraint(equalTo: widthAnchor, multiplier: 1)
|
||||||
layer.setNeedsDisplay()
|
heightConstraint?.isActive = true
|
||||||
|
isAccessibilityElement = true
|
||||||
|
accessibilityHint = MVMCoreUIUtility.hardcodedString(withKey: "heart_action_hint")
|
||||||
|
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]?) {
|
||||||
@ -77,6 +89,22 @@ open class Heart: Control {
|
|||||||
guard let model = model as? HeartModel else { return }
|
guard let model = model as? HeartModel else { return }
|
||||||
isSelected = model.isActive
|
isSelected = model.isActive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Methods
|
||||||
|
//--------------------------------------------------
|
||||||
|
/// Adjust accessibility label based on selection of Heart.
|
||||||
|
func updateAccessibilityLabel() {
|
||||||
|
if let message = MVMCoreUIUtility.hardcodedString(withKey: "heart"),
|
||||||
|
let selectedState = MVMCoreUIUtility.hardcodedString(withKey: isSelected ? "heart_selected_state" : "heart_not_selected_state") {
|
||||||
|
accessibilityLabel = message + selectedState
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func tapAction() {
|
||||||
|
isSelected = !isSelected
|
||||||
|
setNeedsDisplay()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Int {
|
extension Int {
|
||||||
|
|||||||
@ -67,6 +67,11 @@
|
|||||||
"AccOff" = "off";
|
"AccOff" = "off";
|
||||||
"AccToggleHint" = "double tap to toggle";
|
"AccToggleHint" = "double tap to toggle";
|
||||||
|
|
||||||
|
// MARK: Heart
|
||||||
|
"heart" = "Heart";
|
||||||
|
"heart_action_hint" = "Double tap to select";
|
||||||
|
"heart_selected_state" = "Selected";
|
||||||
|
"heart_not_selected_state" = "Not Selected";
|
||||||
|
|
||||||
// MARK: Carousel
|
// MARK: Carousel
|
||||||
"MVMCoreUIPageControl_currentpage_index" = "page %@ of %d";
|
"MVMCoreUIPageControl_currentpage_index" = "page %@ of %d";
|
||||||
|
|||||||
@ -49,6 +49,10 @@
|
|||||||
"AccOn" = "encendido";
|
"AccOn" = "encendido";
|
||||||
"AccOff" = "apagado";
|
"AccOff" = "apagado";
|
||||||
"AccToggleHint" = "toca dos veces para alternar";
|
"AccToggleHint" = "toca dos veces para alternar";
|
||||||
|
// Heart
|
||||||
|
"heart_action_hint" = "Toca dos veces para seleccionar.";
|
||||||
|
"heart_selected_state" = "Seleccionado";
|
||||||
|
"heart_not_selected_state" = "No Seleccionado";
|
||||||
// Carousel
|
// Carousel
|
||||||
"MVMCoreUIPageControl_currentpage_index" = "página %@ de %d";
|
"MVMCoreUIPageControl_currentpage_index" = "página %@ de %d";
|
||||||
"MVMCoreUIPageControlslides_currentpage_index" = "diapositiva %@ of %d";
|
"MVMCoreUIPageControlslides_currentpage_index" = "diapositiva %@ of %d";
|
||||||
|
|||||||
@ -51,6 +51,12 @@
|
|||||||
"AccOn" = "encendido";
|
"AccOn" = "encendido";
|
||||||
"AccOff" = "apagado";
|
"AccOff" = "apagado";
|
||||||
"AccToggleHint" = "toca dos veces para alternar";
|
"AccToggleHint" = "toca dos veces para alternar";
|
||||||
|
|
||||||
|
// Heart
|
||||||
|
"heart_action_hint" = "Toca dos veces para seleccionar.";
|
||||||
|
"heart_selected_state" = "Seleccionado";
|
||||||
|
"heart_not_selected_state" = "No Seleccionado";
|
||||||
|
|
||||||
// Carousel
|
// Carousel
|
||||||
"MVMCoreUIPageControl_currentpage_index" = "página %@ de %d";
|
"MVMCoreUIPageControl_currentpage_index" = "página %@ de %d";
|
||||||
"MVMCoreUIPageControlslides_currentpage_index" = "diapositiva %@ of %d";
|
"MVMCoreUIPageControlslides_currentpage_index" = "diapositiva %@ of %d";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user