FLEXShortcutsSection.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // FLEXShortcutsSection.h
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 8/29/19.
  6. // Copyright © 2020 FLEX Team. 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. ///
  56. /// When you hide the disclosure indicator, the row is not selectable.
  57. - (UITableViewCellAccessoryType)accessoryTypeForRow:(NSInteger)row;
  58. /// The number of lines for the title and subtitle labels. Defaults to 1.
  59. @property (nonatomic, readonly) NSInteger numberOfLines;
  60. /// The object used to initialize this section.
  61. @property (nonatomic, readonly) id object;
  62. /// Whether dynamic subtitles should always be computed as a cell is configured.
  63. /// Defaults to NO. Has no effect on static subtitles that are passed explicitly.
  64. @property (nonatomic) BOOL cacheSubtitles;
  65. @end
  66. @class FLEXShortcutsFactory;
  67. typedef FLEXShortcutsFactory *(^FLEXShortcutsFactoryNames)(NSArray *names);
  68. typedef void (^FLEXShortcutsFactoryTarget)(Class targetClass);
  69. /// The block properties below are to be used like SnapKit or Masonry.
  70. /// \c FLEXShortcutsSection.append.properties(@[@"frame",@"bounds"]).forClass(UIView.class);
  71. ///
  72. /// To safely register your own classes at launch, subclass this class,
  73. /// override \c +load, and call the appropriate methods on \c self
  74. @interface FLEXShortcutsFactory : NSObject
  75. /// Returns the list of all registered shortcuts for the given object in this order:
  76. /// Properties, ivars, methods.
  77. ///
  78. /// This method traverses up the object's class hierarchy until it finds
  79. /// something registered. This allows you to show different shortcuts for
  80. /// the same object in different parts of the class hierarchy.
  81. ///
  82. /// As an example, UIView may have a -layer shortcut registered. But if
  83. /// you're inspecting a UIControl, you may not care about the layer or other
  84. /// UIView-specific things; you might rather see the target-actions registered
  85. /// for this control, and so you would register that property or ivar to UIControl,
  86. /// And you would still be able to see the UIView-registered shorcuts by clicking
  87. /// on the UIView "lens" at the top the explorer view controller screen.
  88. + (NSArray *)shortcutsForObjectOrClass:(id)objectOrClass;
  89. @property (nonatomic, readonly, class) FLEXShortcutsFactory *append;
  90. @property (nonatomic, readonly, class) FLEXShortcutsFactory *prepend;
  91. @property (nonatomic, readonly, class) FLEXShortcutsFactory *replace;
  92. @property (nonatomic, readonly) FLEXShortcutsFactoryNames properties;
  93. /// Do not try to set \c classProperties at the same time as \c ivars or other instance things.
  94. @property (nonatomic, readonly) FLEXShortcutsFactoryNames classProperties;
  95. @property (nonatomic, readonly) FLEXShortcutsFactoryNames ivars;
  96. @property (nonatomic, readonly) FLEXShortcutsFactoryNames methods;
  97. /// Do not try to set \c classMethods at the same time as \c ivars or other instance things.
  98. @property (nonatomic, readonly) FLEXShortcutsFactoryNames classMethods;
  99. /// Accepts the target class. If you pass a regular class object,
  100. /// shortcuts will appear on instances. If you pass a metaclass object,
  101. /// shortcuts will appear when exploring a class object.
  102. ///
  103. /// For example, some class method shortcuts are added to the NSObject meta
  104. /// class by default so that you can see +alloc and +new when exploring
  105. /// a class object. If you wanted these to show up when exploring
  106. /// instances you would pass them to the classMethods method above.
  107. @property (nonatomic, readonly) FLEXShortcutsFactoryTarget forClass;
  108. @end