FLEXShortcut.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // FLEXShortcut.h
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 12/10/19.
  6. // Copyright © 2019 Flipboard. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.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 <NSObject>
  19. - (nonnull NSString *)titleWith:(id)object;
  20. - (nullable NSString *)subtitleWith:(id)object;
  21. //- (void (^)(UIViewController *))didSelectAction:(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. @optional
  27. /// Called when the (i) button is pressed if the accessory type includes it
  28. - (UIViewController *)editorWith:(id)object;
  29. @end
  30. /// Provides default behavior for FLEX metadata objects. Also works in a limited way with strings.
  31. /// Used internally. If you wish to use this object, only pass in \c FLEX* metadata objects.
  32. @interface FLEXShortcut : NSObject <FLEXShortcut>
  33. /// @param item An \c NSString or \c FLEX* metadata object.
  34. /// @note You may also pass a \c FLEXShortcut conforming object,
  35. /// and that object will be returned instead.
  36. + (id<FLEXShortcut>)shortcutFor:(id)item;
  37. @end
  38. /// Provides a quick and dirty implementation of the \c FLEXShortcut protocol,
  39. /// allowing you to specify a static title and dynamic atttributes for everything else.
  40. /// The object passed into each block is the object passed to each \c FLEXShortcut method.
  41. ///
  42. /// Does not support the \c -editorWith: method.
  43. @interface FLEXActionShortcut : NSObject <FLEXShortcut>
  44. + (instancetype)title:(NSString *)title
  45. subtitle:(nullable NSString *(^)(id object))subtitleFuture
  46. viewer:(nullable UIViewController *(^)(id object))viewerFuture
  47. accessoryType:(nullable UITableViewCellAccessoryType(^)(id object))accessoryTypeFuture;
  48. @end
  49. NS_ASSUME_NONNULL_END