From 4f982072c4374de9ded7454fcbeeedb8c7ba1ff0 Mon Sep 17 00:00:00 2001 From: Alex Odawa Date: Tue, 5 Mar 2024 21:21:56 +0100 Subject: [PATCH] reorder control --- .../Sources/ListReorderGesture.swift | 65 +++++++++++++++---- Demo/Demo.xcodeproj/project.pbxproj | 4 +- .../CollectionViewAppearance.swift | 10 +-- 3 files changed, 59 insertions(+), 20 deletions(-) diff --git a/BlueprintUILists/Sources/ListReorderGesture.swift b/BlueprintUILists/Sources/ListReorderGesture.swift index 84384943e..2b2c1304b 100644 --- a/BlueprintUILists/Sources/ListReorderGesture.swift +++ b/BlueprintUILists/Sources/ListReorderGesture.swift @@ -81,8 +81,12 @@ public struct ListReorderGesture : Element // MARK: Element // +// public var content: ElementContent { +// ElementContent(child: self.element) +// } + public var content: ElementContent { - ElementContent(child: self.element) + ElementContent(measuring: self.element) } public func backingViewDescription(with context: ViewDescriptionContext) -> ViewDescription? @@ -93,18 +97,7 @@ public struct ListReorderGesture : Element } config.apply { view in - view.isAccessibilityElement = true - view.accessibilityLabel = ListableLocalizedStrings.ReorderGesture.accessibilityLabel - view.accessibilityValue = reorderItemAccessibilityLabel - view.accessibilityHint = ListableLocalizedStrings.ReorderGesture.accessibilityHint - view.accessibilityTraits.formUnion(.button) - view.accessibilityCustomActions = accessibilityActions() - - view.recognizer.isEnabled = self.isEnabled - - view.recognizer.apply(actions: self.actions) - - view.recognizer.minimumPressDuration = begins == .onLongPress ? 0.5 : 0.0 + view.apply(self) } } } @@ -129,8 +122,11 @@ fileprivate extension ListReorderGesture { private final class View : UIView { - let recognizer : ItemReordering.GestureRecognizer + let blueprintView = BlueprintView() + + let recognizer : ItemReordering.GestureRecognizer + private lazy var proxyElement = UIAccessibilityElement(accessibilityContainer: self) init(frame: CGRect, wrapping : ListReorderGesture) { self.recognizer = .init() @@ -142,12 +138,53 @@ fileprivate extension ListReorderGesture self.backgroundColor = .clear self.addGestureRecognizer(self.recognizer) + + self.isAccessibilityElement = false + + addSubview(blueprintView) + blueprintView.backgroundColor = .clear } @available(*, unavailable) required init?(coder aDecoder: NSCoder) { listableInternalFatal() } + + override func layoutSubviews() { + super.layoutSubviews() + blueprintView.frame = bounds + proxyElement.accessibilityFrame = accessibilityFrame + proxyElement.accessibilityActivationPoint = accessibilityActivationPoint + } + + func apply(_ model: ListReorderGesture) { + blueprintView.element = model.element + + proxyElement.accessibilityLabel = ListableLocalizedStrings.ReorderGesture.accessibilityLabel + proxyElement.accessibilityValue = model.reorderItemAccessibilityLabel + proxyElement.accessibilityHint = ListableLocalizedStrings.ReorderGesture.accessibilityHint + proxyElement.accessibilityTraits.formUnion(.button) + proxyElement.accessibilityCustomActions = model.accessibilityActions() + + proxyElement.accessibilityFrame = self.accessibilityFrame + proxyElement.accessibilityActivationPoint = self.accessibilityActivationPoint + + + recognizer.isEnabled = model.isEnabled + + recognizer.apply(actions: model.actions) + + recognizer.minimumPressDuration = model.begins == .onLongPress ? 0.5 : 0.0 + } + + override var accessibilityElements: [Any]? { + get { + return [blueprintView, proxyElement] + } + set { + fatalError("Cannot set accessibility elements directly") + } + } } } diff --git a/Demo/Demo.xcodeproj/project.pbxproj b/Demo/Demo.xcodeproj/project.pbxproj index 575ee9a79..4efdb541f 100644 --- a/Demo/Demo.xcodeproj/project.pbxproj +++ b/Demo/Demo.xcodeproj/project.pbxproj @@ -684,7 +684,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 2HQ24J954F; + DEVELOPMENT_TEAM = Y4XC6NM5DD; INFOPLIST_FILE = Demo/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -703,7 +703,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 2HQ24J954F; + DEVELOPMENT_TEAM = Y4XC6NM5DD; INFOPLIST_FILE = Demo/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", diff --git a/Demo/Sources/Demos/Demo Screens/CollectionViewAppearance.swift b/Demo/Sources/Demos/Demo Screens/CollectionViewAppearance.swift index 6cc4c9d94..2f30293b2 100644 --- a/Demo/Sources/Demos/Demo Screens/CollectionViewAppearance.swift +++ b/Demo/Sources/Demos/Demo Screens/CollectionViewAppearance.swift @@ -142,10 +142,12 @@ struct DemoItem : BlueprintItemContent, Equatable, LocalizedCollatableItemConten if info.isReorderable { row.addFixed( - child: Image( - image: UIImage(named: "ReorderControl"), - contentMode: .center - ) + child: + Image( + image: UIImage(named: "ReorderControl"), + contentMode: .center + ) + .accessibilityElement(label: "test label", value: "value", traits: [.selected]) .listReorderGesture(with: info.reorderingActions, begins: requiresLongPress ? .onLongPress : .onTap) ) }