deep-linking-sample/Apps/Wikipedia/WMF Framework/LabelGroupAccessibilityElement.swift
Javier Cicchelli 9bcdaa697b [Setup] Basic project structure (#1)
This PR contains all the work related to setting up this project as required to implement the [Assignment](https://repo.rock-n-code.com/rock-n-code/deep-linking-assignment/wiki/Assignment) on top, as intended.

To summarise this work:
- [x] created a new **Xcode** project;
- [x] cloned the `Wikipedia` app and inserted it into the **Xcode** project;
- [x] created the `Locations` app and also, its `Libraries` package;
- [x] created the `Shared` package to share dependencies between the apps;
- [x] added a `Makefile` file and implemented some **environment** and **help** commands.

Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Reviewed-on: rock-n-code/deep-linking-assignment#1
2023-04-08 18:37:13 +00:00

43 lines
1.5 KiB
Swift

import UIKit
public class LabelGroupAccessibilityElement: UIAccessibilityElement {
let labels: [UILabel]
weak var view: UIView?
public init(view: UIView, labels: [UILabel], actions: [UIAccessibilityCustomAction]) {
self.labels = labels
self.view = view
super.init(accessibilityContainer: view)
isAccessibilityElement = true
accessibilityTraits = UIAccessibilityTraits.link
accessibilityCustomActions = actions
update()
}
func update() {
guard let firstLabel = labels.first else {
return
}
var combinedLabel: String = ""
if let accessibilityLabel = firstLabel.accessibilityLabel {
combinedLabel = accessibilityLabel
} else if let text = firstLabel.text {
combinedLabel = text
}
var combinedFrame = firstLabel.frame
for label in labels[1..<labels.count] {
combinedFrame = combinedFrame.union(label.frame)
var maybeLabelLine: String? = label.accessibilityLabel
if maybeLabelLine == nil {
maybeLabelLine = label.text
}
if let labelLine: String = maybeLabelLine, (labelLine as NSString).length > 0 {
combinedLabel.append("\n")
combinedLabel.append(labelLine)
}
}
self.accessibilityFrameInContainerSpace = combinedFrame
self.accessibilityLabel = combinedLabel
}
}