From 1b10c21100a9bb2d61a00225e8a307a2f747fd7b Mon Sep 17 00:00:00 2001 From: Keerthy Date: Mon, 26 Feb 2024 23:48:28 +0530 Subject: [PATCH 1/3] Added customActions to checkBoxLabel --- .../Atomic/Atoms/Views/CheckboxLabel.swift | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/CheckboxLabel.swift b/MVMCoreUI/Atomic/Atoms/Views/CheckboxLabel.swift index 965656a6..f0d47ea3 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CheckboxLabel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CheckboxLabel.swift @@ -15,6 +15,7 @@ public let checkbox = Checkbox() public let label = Label(fontStyle: .RegularBodySmall) private var observation: NSKeyValueObservation? = nil + public var clauses: [Label.ActionableClause] = [] //-------------------------------------------------- // MARK: - Properties @@ -43,7 +44,7 @@ addSubview(label) label.text = "" - + accessibilityCustomActions = [] checkbox.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true checkboxBottomConstraint = layoutMarginsGuide.bottomAnchor.constraint(equalTo: checkbox.bottomAnchor) @@ -139,6 +140,26 @@ open func updateAccessibilityLabel() { checkbox.updateAccessibilityLabel() + isAccessibilityElement = true + if !label.clauses.isEmpty { + accessibilityHint?.append(", \(String(format: (MVMCoreUIUtility.hardcodedString(withKey: "swipe_to_select_with_action_hint")) ?? "") )") + + for clause in label.clauses { + let actionText = NSString(string: label.text ?? "").substring(with: clause.range) + let accessibleAction = UIAccessibilityCustomAction(name: actionText, target: self, selector: #selector(accessibilityCustomAction(_:))) + self.clauses.append(Label.ActionableClause.init(range: clause.range, actionBlock: clause.actionBlock, accessibilityID: accessibleAction.hash)) + accessibilityCustomActions?.append(accessibleAction) + } + } accessibilityLabel = [checkbox.accessibilityLabel, label.text].compactMap { $0 }.joined(separator: ",") } + + @objc public func accessibilityCustomAction(_ action: UIAccessibilityCustomAction) { + for clause in self.clauses { + if action.hash == clause.accessibilityID { + clause.performAction() + return + } + } + } } From d99a7ee546935756c0439724eea6e6194a8c26e2 Mon Sep 17 00:00:00 2001 From: Keerthy Date: Wed, 6 Mar 2024 23:55:15 +0530 Subject: [PATCH 2/3] Updated logic Updated access to children instead of parent --- .../Atomic/Atoms/Views/CheckboxLabel.swift | 30 ++++--------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Views/CheckboxLabel.swift b/MVMCoreUI/Atomic/Atoms/Views/CheckboxLabel.swift index f0d47ea3..10b0a105 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/CheckboxLabel.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/CheckboxLabel.swift @@ -15,7 +15,6 @@ public let checkbox = Checkbox() public let label = Label(fontStyle: .RegularBodySmall) private var observation: NSKeyValueObservation? = nil - public var clauses: [Label.ActionableClause] = [] //-------------------------------------------------- // MARK: - Properties @@ -44,7 +43,6 @@ addSubview(label) label.text = "" - accessibilityCustomActions = [] checkbox.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true checkboxBottomConstraint = layoutMarginsGuide.bottomAnchor.constraint(equalTo: checkbox.bottomAnchor) @@ -65,9 +63,8 @@ bottomLabelConstraint.isActive = true alignCheckbox(.center) - isAccessibilityElement = true - accessibilityHint = checkbox.accessibilityHint - accessibilityTraits = checkbox.accessibilityTraits + isAccessibilityElement = false + accessibilityElements = [checkbox, label] observation = observe(\.checkbox.isSelected, options: [.new]) { [weak self] _, _ in self?.updateAccessibilityLabel() } @@ -140,26 +137,9 @@ open func updateAccessibilityLabel() { checkbox.updateAccessibilityLabel() - isAccessibilityElement = true - if !label.clauses.isEmpty { - accessibilityHint?.append(", \(String(format: (MVMCoreUIUtility.hardcodedString(withKey: "swipe_to_select_with_action_hint")) ?? "") )") - - for clause in label.clauses { - let actionText = NSString(string: label.text ?? "").substring(with: clause.range) - let accessibleAction = UIAccessibilityCustomAction(name: actionText, target: self, selector: #selector(accessibilityCustomAction(_:))) - self.clauses.append(Label.ActionableClause.init(range: clause.range, actionBlock: clause.actionBlock, accessibilityID: accessibleAction.hash)) - accessibilityCustomActions?.append(accessibleAction) - } - } - accessibilityLabel = [checkbox.accessibilityLabel, label.text].compactMap { $0 }.joined(separator: ",") - } - - @objc public func accessibilityCustomAction(_ action: UIAccessibilityCustomAction) { - for clause in self.clauses { - if action.hash == clause.accessibilityID { - clause.performAction() - return - } + + if let text = label.text { + checkbox.accessibilityLabel?.append(", \(text)") } } } From 09081b8bc80551f6d0475f138d2222a9e9947ebc Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 14 Mar 2024 14:31:57 -0500 Subject: [PATCH 3/3] added the fontSize as a last resort for vars being set in the Label after fontStyle and fontName. Signed-off-by: Matt Bruce --- MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift index 0b12b5a9..d8c114f8 100644 --- a/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift +++ b/MVMCoreUI/Atomic/Atoms/Views/Label/Label.swift @@ -209,6 +209,9 @@ public typealias ActionBlock = () -> () if let newFont = UIFont(name: fontName, size: fontSize ?? standardFontSize) { font = newFont } + } else if let fontSize = viewModel.fontSize { + standardFontSize = fontSize + font = textStyle.font.withSize(fontSize) } if let color = viewModel.textColor {