Skip to content

Commit

Permalink
addressing feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyalPineapple committed Mar 19, 2024
1 parent 4e398e6 commit f6057ff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
41 changes: 25 additions & 16 deletions BlueprintUILists/Sources/ListReorderGesture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,22 @@ public struct ListReorderGesture : Element
//

public var content: ElementContent {
ElementContent(measuring: self.element)
ElementContent(child: self.element)
}

public func backingViewDescription(with context: ViewDescriptionContext) -> ViewDescription?
{
return ViewDescription(View.self) { config in

config.builder = {
View(frame: context.bounds, wrapping: self)
}
config.contentView = { $0.containerView }

config.apply { view in
view.apply(self)
}

}
}

Expand Down Expand Up @@ -128,26 +131,28 @@ fileprivate extension ListReorderGesture
private final class View : UIView
{

let blueprintView = BlueprintView()
let containerView = UIView()
let recognizer : ItemReordering.GestureRecognizer
private lazy var proxyElement = UIAccessibilityElement(accessibilityContainer: self)
private var minimumPressDuration: TimeInterval = 0.0 {
didSet {
if !UIAccessibility.isVoiceOverRunning {
recognizer.minimumPressDuration = minimumPressDuration
}
updateGesturePressDuration()
}
}

private func updateGesturePressDuration() {
self.recognizer.minimumPressDuration = UIAccessibility.isVoiceOverRunning ? 0.0 : self.minimumPressDuration
}

var notificationToken: Any?
init(frame: CGRect, wrapping : ListReorderGesture)
{
self.recognizer = .init()

super.init(frame: frame)
recognizer.accessibilityProxy = proxyElement
NotificationCenter.default.addObserver(forName: UIAccessibility.voiceOverStatusDidChangeNotification, object: nil, queue: nil) { [weak self] notification in
guard let self = self else { return }
self.recognizer.minimumPressDuration = UIAccessibility.isVoiceOverRunning ? 0.0 : self.minimumPressDuration
notificationToken = NotificationCenter.default.addObserver(forName: UIAccessibility.voiceOverStatusDidChangeNotification, object: nil, queue: nil) { [weak self] notification in
self?.updateGesturePressDuration()
}

self.isOpaque = false
Expand All @@ -158,9 +163,15 @@ fileprivate extension ListReorderGesture

self.isAccessibilityElement = false

blueprintView.isOpaque = false
blueprintView.backgroundColor = .clear
addSubview(blueprintView)
containerView.isOpaque = false
containerView.backgroundColor = .clear
addSubview(containerView)
}

deinit {
if let token = notificationToken {
NotificationCenter.default.removeObserver(token)
}
}

@available(*, unavailable)
Expand All @@ -169,8 +180,6 @@ fileprivate extension ListReorderGesture
}

func apply(_ model: ListReorderGesture) {
blueprintView.element = model.element

if let itemName = model.reorderItemAccessibilityLabel {
proxyElement.accessibilityLabel = String(format: ListableLocalizedStrings.ReorderGesture.accessibilityLabelFormat, itemName)
} else {
Expand All @@ -189,12 +198,12 @@ fileprivate extension ListReorderGesture

override func layoutSubviews() {
super.layoutSubviews()
blueprintView.frame = bounds
containerView.frame = bounds
}

override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
if UIAccessibility.isVoiceOverRunning,
UIAccessibility.focusedElement(using: nil) as? NSObject == proxyElement {
UIAccessibility.focusedElement(using: .notificationVoiceOver) as? NSObject == proxyElement {
// Intercept touch events to avoid activating contained elements.
return self
}
Expand All @@ -206,7 +215,7 @@ fileprivate extension ListReorderGesture
get {
proxyElement.accessibilityFrame = self.accessibilityFrame
proxyElement.accessibilityActivationPoint = self.accessibilityActivationPoint
return [blueprintView, proxyElement]
return [containerView, proxyElement]
}
set {
fatalError("Cannot set accessibility elements directly")
Expand Down
2 changes: 1 addition & 1 deletion ListableUI/Sources/Item/ItemReordering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ extension ItemReordering {
guard UIAccessibility.isVoiceOverRunning, let proxy = accessibilityProxy else {
return true
}
return UIAccessibility.focusedElement(using: nil) as? NSObject == proxy
return UIAccessibility.focusedElement(using: .notificationVoiceOver) as? NSObject == proxy
}
}
}
Expand Down

0 comments on commit f6057ff

Please sign in to comment.