Skip to content

Commit

Permalink
Modernize ElementSelectionViewController
Browse files Browse the repository at this point in the history
  • Loading branch information
NickEntin committed Aug 8, 2023
1 parent 091cd71 commit b946860
Showing 1 changed file with 42 additions and 22 deletions.
64 changes: 42 additions & 22 deletions Example/AccessibilitySnapshot/ElementSelectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ final class ElementSelectionViewController: AccessibilityViewController {
// MARK: - Life Cycle

init(configurations: [ViewConfiguration]) {
views = configurations.map { configuration in
super.init(nibName: nil, bundle: nil)

rootView.views = configurations.map { configuration in
let view: UIView
switch configuration {
case let .accessibilityElement(accessibilityElementsHidden: accessibilityElementsHidden, isHidden: isHidden):
Expand All @@ -70,15 +72,13 @@ final class ElementSelectionViewController: AccessibilityViewController {
view.isHidden = isHidden
}

view.frame.size = CGSize(width: 64, height: 64)
view.bounds.size = CGSize(width: 64, height: 64)
view.layer.cornerRadius = 32
view.backgroundColor = .lightGray
view.accessibilityLabel = "Lorem ipsum"

return view
}

super.init(nibName: nil, bundle: nil)
}

@available(*, unavailable)
Expand All @@ -88,27 +88,14 @@ final class ElementSelectionViewController: AccessibilityViewController {

// MARK: - Private Properties

private let views: [UIView]

// MARK: - UIViewController

override func viewDidLoad() {
super.viewDidLoad()

views.forEach { view.addSubview($0) }
private var rootView: View {
return view as! View
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

let statusBarHeight = UIApplication.shared.statusBarFrame.height
// MARK: - UIViewController

var distributionSpecifiers: [ViewDistributionSpecifying] = [ statusBarHeight.fixed, 1.flexible ]
for subview in views {
distributionSpecifiers.append(subview)
distributionSpecifiers.append(1.flexible)
}
view.applySubviewDistribution(distributionSpecifiers)
override func loadView() {
view = View()
}

}
Expand Down Expand Up @@ -212,6 +199,39 @@ extension ElementSelectionViewController {

// MARK: -

private extension ElementSelectionViewController {

final class View: UIView {

// MARK: - Public Properties

var views: [UIView] = [] {
didSet {
oldValue.forEach { $0.removeFromSuperview() }
views.forEach { addSubview($0) }
setNeedsLayout()
}
}

// MARK: - UIView

override func layoutSubviews() {
let statusBarHeight = window?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0

var distributionSpecifiers: [ViewDistributionSpecifying] = [ statusBarHeight.fixed, 1.flexible ]
for subview in views {
distributionSpecifiers.append(subview)
distributionSpecifiers.append(1.flexible)
}
applySubviewDistribution(distributionSpecifiers)
}

}

}

// MARK: -

private final class AccessibilityContainerView: UIView {

// MARK: - Life Cycle
Expand Down

0 comments on commit b946860

Please sign in to comment.