FLEXShortcutsSection.h 5.8 KB

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