FLEXShortcut.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // FLEXShortcut.h
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 12/10/19.
  6. // Copyright © 2020 FLEX Team. All rights reserved.
  7. //
  8. #import "FLEXObjectExplorer.h"
  9. NS_ASSUME_NONNULL_BEGIN
  10. /// Represents a row in a shortcut section.
  11. ///
  12. /// The purpsoe of this protocol is to allow delegating a small
  13. /// subset of the responsibilities of a \c FLEXShortcutsSection
  14. /// to another object, for a single arbitrary row.
  15. ///
  16. /// It is useful to make your own shortcuts to append/prepend
  17. /// them to the existing list of shortcuts for a class.
  18. @protocol FLEXShortcut <FLEXObjectExplorerItem>
  19. - (nonnull NSString *)titleWith:(id)object;
  20. - (nullable NSString *)subtitleWith:(id)object;
  21. - (nullable void (^)(UIViewController *host))didSelectActionWith:(id)object;
  22. /// Called when the row is selected
  23. - (nullable UIViewController *)viewerWith:(id)object;
  24. /// Basically, whether or not to show a detail disclosure indicator
  25. - (UITableViewCellAccessoryType)accessoryTypeWith:(id)object;
  26. /// If nil is returned, the default reuse identifier is used
  27. - (nullable NSString *)customReuseIdentifierWith:(id)object;
  28. @optional
  29. /// Called when the (i) button is pressed if the accessory type includes it
  30. - (UIViewController *)editorWith:(id)object forSection:(FLEXTableViewSection *)section;
  31. @end
  32. /// Provides default behavior for FLEX metadata objects. Also works in a limited way with strings.
  33. /// Used internally. If you wish to use this object, only pass in \c FLEX* metadata objects.
  34. @interface FLEXShortcut : NSObject <FLEXShortcut>
  35. /// @param item An \c NSString or \c FLEX* metadata object.
  36. /// @note You may also pass a \c FLEXShortcut conforming object,
  37. /// and that object will be returned instead.
  38. + (id<FLEXShortcut>)shortcutFor:(id)item;
  39. @end
  40. /// Provides a quick and dirty implementation of the \c FLEXShortcut protocol,
  41. /// allowing you to specify a static title and dynamic atttributes for everything else.
  42. /// The object passed into each block is the object passed to each \c FLEXShortcut method.
  43. ///
  44. /// Does not support the \c -editorWith: method.
  45. @interface FLEXActionShortcut : NSObject <FLEXShortcut>
  46. + (instancetype)title:(NSString *)title
  47. subtitle:(nullable NSString *(^)(id object))subtitleFuture
  48. viewer:(nullable UIViewController *(^)(id object))viewerFuture
  49. accessoryType:(nullable UITableViewCellAccessoryType(^)(id object))accessoryTypeFuture;
  50. + (instancetype)title:(NSString *)title
  51. subtitle:(nullable NSString *(^)(id object))subtitleFuture
  52. selectionHandler:(nullable void (^)(UIViewController *host, id object))tapAction
  53. accessoryType:(nullable UITableViewCellAccessoryType(^)(id object))accessoryTypeFuture;
  54. @end
  55. NS_ASSUME_NONNULL_END