FLEXShortcutsSection.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // FLEXShortcutsSection.h
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 8/29/19.
  6. // Copyright © 2019 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXTableViewSection.h"
  9. #import "FLEXObjectInfoSection.h"
  10. @class FLEXProperty, FLEXIvar, FLEXMethod;
  11. /// An abstract base class for custom object "shortcuts" where every
  12. /// row can possibly have some action. The section title is "Shortcuts".
  13. ///
  14. /// You should only subclass this class if you need simple shortcuts
  15. /// with plain titles and/or subtitles. This class will automatically
  16. /// configure each cell appropriately. Since this is intended as a
  17. /// static section, subclasses should only need to implement the
  18. /// \c viewControllerToPushForRow: and/or \c didSelectRowAction: methods.
  19. ///
  20. /// If you create the section using \c forObject:rows:numberOfLines:
  21. /// then it will provide a view controller from \c viewControllerToPushForRow:
  22. /// automatically for rows that are a property/ivar/method.
  23. @interface FLEXShortcutsSection : FLEXTableViewSection <FLEXObjectInfoSection>
  24. /// Uses \c kFLEXDefaultCell
  25. + (instancetype)forObject:(id)objectOrClass rowTitles:(NSArray<NSString *> *)titles;
  26. /// Uses \c kFLEXDetailCell for non-empty subtitles, otherwise uses \c kFLEXDefaultCell
  27. + (instancetype)forObject:(id)objectOrClass
  28. rowTitles:(NSArray<NSString *> *)titles
  29. rowSubtitles:(NSArray<NSString *> *)subtitles;
  30. /// Uses \c kFLEXDefaultCell for rows that are given a title, otherwise
  31. /// this uses \c kFLEXDetailCell for any other allowed object.
  32. ///
  33. /// The section provide a view controller from \c viewControllerToPushForRow:
  34. /// automatically for rows that are a property/ivar/method.
  35. ///
  36. /// @param rows A mixed array containing any of the following:
  37. /// - any \c FLEXShortcut conforming object
  38. /// - an \c NSString
  39. /// - a \c FLEXProperty
  40. /// - a \c FLEXIvar
  41. /// - a \c FLEXMethodBase (includes \c FLEXMethod of course)
  42. /// Passing one of the latter 3 will provide a shortcut to that property/ivar/method.
  43. /// @return \c nil if no rows are provided
  44. + (instancetype)forObject:(id)objectOrClass rows:(NSArray *)rows;
  45. /// Same as \c forObject:rows: but the given rows are prepended
  46. /// to the shortcuts already registered for the object's class.
  47. /// \c forObject:rows: does not use the registered shortcuts at all.
  48. + (instancetype)forObject:(id)objectOrClass additionalRows:(NSArray *)rows;
  49. /// Calls into \c forObject:rows: using the registered shortcuts for the object's class.
  50. /// @return \c nil if the object has no shortcuts registered at all
  51. + (instancetype)forObject:(id)objectOrClass;
  52. /// Subclasses \e may override this to hide the disclosure indicator
  53. /// for some rows. It is shown for all rows by default, unless
  54. /// you initialize it with \c forObject:rowTitles:rowSubtitles:
  55. - (UITableViewCellAccessoryType)accessoryTypeForRow:(NSInteger)row;
  56. /// The number of lines for the title and subtitle labels. Defaults to 1.
  57. @property (nonatomic, readonly) NSInteger numberOfLines;
  58. /// The object used to initialize this section.
  59. @property (nonatomic, readonly) id object;
  60. /// Whether dynamic subtitles should always be computed as a cell is configured.
  61. /// Defaults to NO. Has no effect on static subtitles that are passed explicitly.
  62. @property (nonatomic) BOOL cacheSubtitles;
  63. @end
  64. @class FLEXShortcutsFactory;
  65. typedef FLEXShortcutsFactory *(^FLEXShortcutsFactoryNames)(NSArray *names);
  66. typedef void (^FLEXShortcutsFactoryTarget)(Class targetClass);
  67. /// The block properties below are to be used like SnapKit or Masonry.
  68. /// \c FLEXShortcutsSection.append.properties(@[@"frame",@"bounds"]).forClass(UIView.class);
  69. ///
  70. /// To safely register your own classes at launch, subclass this class,
  71. /// override \c +load, and call the appropriate methods on \c self
  72. @interface FLEXShortcutsFactory : NSObject
  73. /// Returns the list of all registered shortcuts for the given object in this order:
  74. /// Properties, ivars, methods.
  75. ///
  76. /// This method traverses up the object's class hierarchy until it finds
  77. /// something registered. This allows you to show different shortcuts for
  78. /// the same object in different parts of the class hierarchy.
  79. ///
  80. /// As an example, UIView may have a -layer shortcut registered. But if
  81. /// you're inspecting a UIControl, you may not care about the layer or other
  82. /// UIView-specific things; you might rather see the target-actions registered
  83. /// for this control, and so you would register that property or ivar to UIControl,
  84. /// And you would still be able to see the UIView-registered shorcuts by clicking
  85. /// on the UIView "lens" at the top the explorer view controller screen.
  86. + (NSArray *)shortcutsForObjectOrClass:(id)objectOrClass;
  87. @property (nonatomic, readonly, class) FLEXShortcutsFactory *append;
  88. @property (nonatomic, readonly, class) FLEXShortcutsFactory *prepend;
  89. @property (nonatomic, readonly, class) FLEXShortcutsFactory *replace;
  90. @property (nonatomic, readonly) FLEXShortcutsFactoryNames properties;
  91. /// Do not try to set \c classProperties at the same time as \c ivars or other instance things.
  92. @property (nonatomic, readonly) FLEXShortcutsFactoryNames classProperties;
  93. @property (nonatomic, readonly) FLEXShortcutsFactoryNames ivars;
  94. @property (nonatomic, readonly) FLEXShortcutsFactoryNames methods;
  95. /// Do not try to set \c classMethods at the same time as \c ivars or other instance things.
  96. @property (nonatomic, readonly) FLEXShortcutsFactoryNames classMethods;
  97. /// Accepts the target class. If you pass a regular class object,
  98. /// shortcuts will appear on instances. If you pass a metaclass object,
  99. /// shortcuts will appear when exploring a class object.
  100. ///
  101. /// For example, some class method shortcuts are added to the NSObject meta
  102. /// class by default so that you can see +alloc and +new when exploring
  103. /// a class object. If you wanted these to show up when exploring
  104. /// instances you would pass them to the classMethods method above.
  105. @property (nonatomic, readonly) FLEXShortcutsFactoryTarget forClass;
  106. @end