TableViewControllerNavigateable.swift 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // TableViewControllerNavigateable.swift
  3. // Mastodon
  4. //
  5. // Created by MainasuK Cirno on 2021-5-21.
  6. //
  7. import os.log
  8. import UIKit
  9. import MastodonAsset
  10. import MastodonLocalization
  11. typealias TableViewControllerNavigateable = TableViewControllerNavigateableCore & TableViewControllerNavigateableRelay
  12. protocol TableViewControllerNavigateableCore: AnyObject {
  13. var tableView: UITableView { get }
  14. var overrideNavigationScrollPosition: UITableView.ScrollPosition? { get set }
  15. var navigationKeyCommands: [UIKeyCommand] { get }
  16. func navigateKeyCommandHandler(_ sender: UIKeyCommand)
  17. func navigate(direction: TableViewNavigationDirection)
  18. func open()
  19. func back()
  20. }
  21. extension TableViewControllerNavigateableCore {
  22. var overrideNavigationScrollPosition: UITableView.ScrollPosition? {
  23. get { return nil }
  24. set { }
  25. }
  26. }
  27. @objc protocol TableViewControllerNavigateableRelay: AnyObject {
  28. func navigateKeyCommandHandlerRelay(_ sender: UIKeyCommand)
  29. }
  30. enum TableViewNavigationDirection {
  31. case up
  32. case down
  33. }
  34. enum TableViewNavigation: String, CaseIterable {
  35. case up
  36. case down
  37. case back // pop
  38. case open
  39. var title: String {
  40. switch self {
  41. case .up: return L10n.Common.Controls.Actions.previous
  42. case .down: return L10n.Common.Controls.Actions.next
  43. case .back: return L10n.Common.Controls.Actions.back
  44. case .open: return L10n.Common.Controls.Actions.open
  45. }
  46. }
  47. // UIKeyCommand input
  48. var input: String {
  49. switch self {
  50. case .up: return "k"
  51. case .down: return "j"
  52. case .back: return "h"
  53. case .open: return "l" // little "L"
  54. }
  55. }
  56. var modifierFlags: UIKeyModifierFlags {
  57. switch self {
  58. case .up: return []
  59. case .down: return []
  60. case .back: return []
  61. case .open: return []
  62. }
  63. }
  64. var propertyList: Any {
  65. return rawValue
  66. }
  67. }