FLEXExplorerSection.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // FLEXExplorerSection.h
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 8/28/19.
  6. // Copyright © 2019 Flipboard. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "FLEXUtility.h"
  10. @class FLEXTableView;
  11. #pragma mark FLEXExplorerSection
  12. /// An abstract base class for custom object explorer sections.
  13. @interface FLEXExplorerSection : NSObject
  14. #pragma mark - Data
  15. /// A title to be displayed for the custom section. Subclasses must override.
  16. @property (nonatomic, readonly) NSString *title;
  17. /// The number of rows in this section.
  18. /// This should not change until \c filterText is changed or \c reloadData is called.
  19. @property (nonatomic, readonly) NSInteger numberOfRows;
  20. /// A map of reuse identifiers to \c UITableViewCell (sub)class objects.
  21. /// Subclasses \e may override this as necessary, but are not required to.
  22. /// See \c FLEXTableView.h for more information.
  23. /// @return nil by default.
  24. @property (nonatomic, readonly) NSDictionary<NSString *, Class> *cellRegistrationMapping;
  25. /// The section should filter itself based on the contents of this property
  26. /// as it is set. If it is set to nil or an empty string, it should not filter.
  27. /// Subclasses should override or observe this property and react to changes.
  28. @property (nonatomic) NSString *filterText;
  29. /// Provides an avenue for the section to change the number of rows.
  30. /// This is called before reloading the table view itself.
  31. - (void)reloadData;
  32. #pragma mark - Row Selection
  33. /// Whether the given row should be selectable, such as if tapping the cell
  34. /// should take the user to a new screen or trigger an action.
  35. /// Subclasses \e may override this as necessary, but are not required to.
  36. /// @return \c NO by default
  37. - (BOOL)canSelectRow:(NSInteger)row;
  38. /// An action "future" to be triggered when the row is selected, if the row
  39. /// supports being selected as indicated by \c canSelectRow:. Subclasses
  40. /// must implement this in accordance with how they implement \c canSelectRow:
  41. /// if they do not implement \c viewControllerToPushForRow:
  42. /// @return This returns \c nil if no view controller is provided by
  43. /// \c viewControllerToPushForRow: — otherwise it pushes that view controller
  44. /// onto \c host.navigationController
  45. - (void(^)(UIViewController *host))didSelectRowAction:(NSInteger)row;
  46. /// A view controller to display when the row is selected, if the row
  47. /// supports being selected as indicated by \c canSelectRow:. Subclasses
  48. /// must implement this in accordance with how they implement \c canSelectRow:
  49. /// if they do not implement \c didSelectRowAction:
  50. /// @return \c nil by default
  51. - (UIViewController *)viewControllerToPushForRow:(NSInteger)row;
  52. /// Called when the accessory view's detail button is pressed.
  53. /// @return \c nil by default.
  54. - (void(^)(UIViewController *host))didPressInfoButtonAction:(NSInteger)row;
  55. #pragma mark - Context Menus
  56. #if FLEX_AT_LEAST_IOS13_SDK
  57. /// By default, this is the title of the row.
  58. /// @return The title of the context menu, if any.
  59. - (NSString *)menuTitleForRow:(NSInteger)row API_AVAILABLE(ios(13.0));
  60. /// Protected, not intended for public use. \c menuTitleForRow:
  61. /// already includes the value returned from this method.
  62. ///
  63. /// By default, this returns \c @"". Subclasses may override to
  64. /// provide a detailed description of the target of the context menu.
  65. - (NSString *)menuSubtitleForRow:(NSInteger)row API_AVAILABLE(ios(13.0));
  66. /// The context menu items, if any. Subclasses may override.
  67. /// By default, only inludes items for \c copyMenuItemsForRow:.
  68. - (NSArray<UIMenuElement *> *)menuItemsForRow:(NSInteger)row sender:(UIViewController *)sender API_AVAILABLE(ios(13.0));
  69. /// Subclasses may override to return a list of copiable items.
  70. ///
  71. /// Every two elements in the list compose a key-value pair, where the key
  72. /// should be a description of what will be copied, and the values should be
  73. /// the strings to copy. Return an empty string as a value to show a disabled action.
  74. - (NSArray<NSString *> *)copyMenuItemsForRow:(NSInteger)row API_AVAILABLE(ios(13.0));
  75. #endif
  76. #pragma mark - Cell Configuration
  77. /// Provide a reuse identifier for the given row. Subclasses should override.
  78. ///
  79. /// Custom reuse identifiers should be specified in \c cellRegistrationMapping.
  80. /// You may return any of the identifiers in \c FLEXTableView.h
  81. /// without including them in the \c cellRegistrationMapping.
  82. /// @return \c kFLEXDefaultCell by default.
  83. - (NSString *)reuseIdentifierForRow:(NSInteger)row;
  84. /// Configure a cell for the given row. Subclasses must override.
  85. - (void)configureCell:(__kindof UITableViewCell *)cell forRow:(NSInteger)row;
  86. #pragma mark - External Convenience
  87. /// For use by whatever view controller uses your section. Not required.
  88. /// @return An optional title.
  89. - (NSString *)titleForRow:(NSInteger)row;
  90. /// For use by whatever view controller uses your section. Not required.
  91. /// @return An optional subtitle.
  92. - (NSString *)subtitleForRow:(NSInteger)row;
  93. @end
  94. #pragma mark - FLEXObjectInfoSection
  95. /// \c FLEXExplorerSection itself doesn't need to know about the object being explored.
  96. /// Subclasses might need this info to provide useful information about the object. Instead
  97. /// of adding an abstract class to the class hierarchy, subclasses can conform to this protocol
  98. /// to indicate that the only info they need to be initialized is the object being explored.
  99. @protocol FLEXObjectInfoSection <NSObject>
  100. + (instancetype)forObject:(id)object;
  101. @end