Skip to content

Commit

Permalink
reorder control
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyalPineapple committed Mar 5, 2024
1 parent 12b5e65 commit 4f98207
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 20 deletions.
65 changes: 51 additions & 14 deletions BlueprintUILists/Sources/ListReorderGesture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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)
}
}
}
Expand All @@ -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()
Expand All @@ -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")
}
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions Demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand All @@ -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)",
Expand Down
10 changes: 6 additions & 4 deletions Demo/Sources/Demos/Demo Screens/CollectionViewAppearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}
Expand Down

0 comments on commit 4f98207

Please sign in to comment.