DragIndicatorView.swift 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // DragIndicatorView.swift
  3. // Mastodon
  4. //
  5. // Created by Cirno MainasuK on 2021-9-14.
  6. //
  7. import UIKit
  8. import MastodonAsset
  9. import MastodonLocalization
  10. final class DragIndicatorView: UIView {
  11. static let height: CGFloat = 38
  12. let barView = UIView()
  13. let separatorLine = UIView.separatorLine
  14. let onDismiss: () -> Void
  15. init(onDismiss: @escaping () -> Void) {
  16. self.onDismiss = onDismiss
  17. super.init(frame: .zero)
  18. _init()
  19. }
  20. required init?(coder: NSCoder) {
  21. fatalError("init(coder:) is not supported")
  22. }
  23. }
  24. extension DragIndicatorView {
  25. private func _init() {
  26. barView.backgroundColor = Asset.Colors.Label.secondary.color
  27. barView.layer.masksToBounds = true
  28. barView.layer.cornerRadius = 2.5
  29. barView.translatesAutoresizingMaskIntoConstraints = false
  30. addSubview(barView)
  31. NSLayoutConstraint.activate([
  32. barView.centerXAnchor.constraint(equalTo: centerXAnchor),
  33. barView.centerYAnchor.constraint(equalTo: centerYAnchor),
  34. barView.heightAnchor.constraint(equalToConstant: 5).priority(.required - 1),
  35. barView.widthAnchor.constraint(equalToConstant: 36).priority(.required - 1),
  36. ])
  37. separatorLine.translatesAutoresizingMaskIntoConstraints = false
  38. addSubview(separatorLine)
  39. NSLayoutConstraint.activate([
  40. separatorLine.leadingAnchor.constraint(equalTo: leadingAnchor),
  41. separatorLine.trailingAnchor.constraint(equalTo: trailingAnchor),
  42. separatorLine.bottomAnchor.constraint(equalTo: bottomAnchor),
  43. separatorLine.heightAnchor.constraint(equalToConstant: UIView.separatorLineHeight(of: self)),
  44. ])
  45. isAccessibilityElement = true
  46. accessibilityTraits = .button
  47. accessibilityLabel = L10n.Scene.AccountList.dismissAccountSwitcher
  48. }
  49. override func accessibilityActivate() -> Bool {
  50. self.onDismiss()
  51. return true
  52. }
  53. }