FLEXRuntime+UIKitHelpers.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // FLEXRuntime+UIKitHelpers.h
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 12/16/19.
  6. // Copyright © 2019 Flipboard. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "FLEXProperty.h"
  10. #import "FLEXIvar.h"
  11. #import "FLEXMethod.h"
  12. #import "FLEXProtocol.h"
  13. @class FLEXObjectExplorerDefaults;
  14. /// Model objects of an object explorer screen adopt this
  15. /// protocol in order respond to user defaults changes
  16. @protocol FLEXObjectExplorerItem <NSObject>
  17. /// Current explorer settings. Set when settings change.
  18. @property (nonatomic) FLEXObjectExplorerDefaults *defaults;
  19. /// YES for properties and ivars which surely support editing, NO for all methods.
  20. @property (nonatomic, readonly) BOOL isEditable;
  21. /// NO for ivars, YES for supported methods and properties
  22. @property (nonatomic, readonly) BOOL isCallable;
  23. @end
  24. @protocol FLEXRuntimeMetadata <FLEXObjectExplorerItem>
  25. /// Used as the main title of the row
  26. - (NSString *)description;
  27. /// Used to compare metadata objects for uniqueness
  28. @property (nonatomic, readonly) NSString *name;
  29. /// For internal use
  30. @property (nonatomic) id tag;
  31. /// Should return \c nil if not applicable
  32. - (id)currentValueWithTarget:(id)object;
  33. /// Used as the subtitle or description of a property, ivar, or method
  34. - (NSString *)previewWithTarget:(id)object;
  35. /// For methods, a method calling screen. For all else, an object explorer.
  36. - (UIViewController *)viewerWithTarget:(id)object;
  37. /// For methods and protocols, nil. For all else, an a field editor screen.
  38. - (UIViewController *)editorWithTarget:(id)object;
  39. /// Used to determine present which interactions are possible to the user
  40. - (UITableViewCellAccessoryType)suggestedAccessoryTypeWithTarget:(id)object;
  41. /// Return nil to use the default reuse identifier
  42. - (NSString *)reuseIdentifierWithTarget:(id)object;
  43. #if FLEX_AT_LEAST_IOS13_SDK
  44. /// An array of actions to place in the first section of the context menu.
  45. - (NSArray<UIAction *> *)additionalActionsWithTarget:(id)object sender:(UIViewController *)sender API_AVAILABLE(ios(13.0));
  46. /// An array where every 2 elements are a key-value pair. The key is a description
  47. /// of what to copy like "Name" and the values are what will be copied.
  48. - (NSArray<NSString *> *)copiableMetadataWithTarget:(id)object;
  49. /// Properties and ivars return the address of an object, if they hold one.
  50. - (NSString *)contextualSubtitleWithTarget:(id)object;
  51. #endif
  52. @end
  53. // Even if a property is readonly, it still may be editable
  54. // via a setter. Checking isEditable will not reflect that
  55. // unless the property was initialized with a class.
  56. @interface FLEXProperty (UIKitHelpers) <FLEXRuntimeMetadata> @end
  57. @interface FLEXIvar (UIKitHelpers) <FLEXRuntimeMetadata> @end
  58. @interface FLEXMethodBase (UIKitHelpers) <FLEXRuntimeMetadata> @end
  59. @interface FLEXMethod (UIKitHelpers) <FLEXRuntimeMetadata> @end
  60. @interface FLEXProtocol (UIKitHelpers) <FLEXRuntimeMetadata> @end
  61. typedef NS_ENUM(NSUInteger, FLEXStaticMetadataRowStyle) {
  62. FLEXStaticMetadataRowStyleSubtitle,
  63. FLEXStaticMetadataRowStyleKeyValue,
  64. FLEXStaticMetadataRowStyleDefault = FLEXStaticMetadataRowStyleSubtitle,
  65. };
  66. /// Displays a small row as a static key-value pair of information.
  67. @interface FLEXStaticMetadata : NSObject <FLEXRuntimeMetadata>
  68. + (instancetype)style:(FLEXStaticMetadataRowStyle)style title:(NSString *)title string:(NSString *)string;
  69. + (instancetype)style:(FLEXStaticMetadataRowStyle)style title:(NSString *)title number:(NSNumber *)number;
  70. + (NSArray<FLEXStaticMetadata *> *)classHierarchy:(NSArray<Class> *)classes;
  71. @end
  72. /// This is assigned to the \c tag property of each metadata.