FLEXCollectionContentSection.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // FLEXCollectionContentSection.h
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 8/28/19.
  6. // Copyright © 2019 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXTableViewSection.h"
  9. #import "FLEXObjectInfoSection.h"
  10. @class FLEXCollectionContentSection, FLEXTableViewCell;
  11. @protocol FLEXCollection, FLEXMutableCollection;
  12. typedef id<FLEXCollection>(^FLEXCollectionContentFuture)(__kindof FLEXCollectionContentSection *section);
  13. #pragma mark Collection
  14. /// A protocol that enables \c FLEXCollectionContentSection to operate on any arbitrary collection.
  15. /// \c NSArray, \c NSDictionary, \c NSSet, and \c NSOrderedSet all conform to this protocol.
  16. @protocol FLEXCollection <NSObject, NSFastEnumeration>
  17. @property (nonatomic, readonly) NSUInteger count;
  18. - (id)copy;
  19. - (id)mutableCopy;
  20. @optional
  21. /// Unordered, unkeyed collections must implement this
  22. @property (nonatomic, readonly) NSArray *allObjects;
  23. /// Keyed collections must implement this and \c objectForKeyedSubscript:
  24. @property (nonatomic, readonly) NSArray *allKeys;
  25. /// Ordered, indexed collections must implement this.
  26. - (id)objectAtIndexedSubscript:(NSUInteger)idx;
  27. /// Keyed, unordered collections must implement this and \c allKeys
  28. - (id)objectForKeyedSubscript:(id)idx;
  29. @end
  30. @protocol FLEXMutableCollection <FLEXCollection>
  31. - (void)filterUsingPredicate:(NSPredicate *)predicate;
  32. @end
  33. @interface NSArray (FLEXCollection) <FLEXCollection> @end
  34. @interface NSSet (FLEXCollection) <FLEXCollection> @end
  35. @interface NSOrderedSet (FLEXCollection) <FLEXCollection> @end
  36. @interface NSDictionary (FLEXCollection) <FLEXCollection> @end
  37. @interface NSMutableArray (FLEXMutableCollection) <FLEXMutableCollection> @end
  38. @interface NSMutableSet (FLEXMutableCollection) <FLEXMutableCollection> @end
  39. @interface NSMutableOrderedSet (FLEXMutableCollection) <FLEXMutableCollection> @end
  40. @interface NSMutableDictionary (FLEXMutableCollection) <FLEXMutableCollection>
  41. - (void)filterUsingPredicate:(NSPredicate *)predicate;
  42. @end
  43. #pragma mark - FLEXCollectionContentSection
  44. /// A custom section for viewing collection elements.
  45. ///
  46. /// Tapping on a row pushes an object explorer for that element.
  47. @interface FLEXCollectionContentSection<__covariant ObjectType> : FLEXTableViewSection <FLEXObjectInfoSection> {
  48. @protected
  49. /// Unused if initialized with a future
  50. id<FLEXCollection> _collection;
  51. /// Unused if initialized with a collection
  52. FLEXCollectionContentFuture _collectionFuture;
  53. /// The filtered collection from \c _collection or \c _collectionFuture
  54. id<FLEXCollection> _cachedCollection;
  55. }
  56. + (instancetype)forCollection:(id<FLEXCollection>)collection;
  57. /// The future given should be safe to call more than once.
  58. /// The result of calling this future multiple times may yield
  59. /// different results each time if the data is changing by nature.
  60. + (instancetype)forReusableFuture:(FLEXCollectionContentFuture)collectionFuture;
  61. /// Defaults to \c NO
  62. @property (nonatomic) BOOL hideSectionTitle;
  63. /// Defaults to \c nil
  64. @property (nonatomic) NSString *customTitle;
  65. /// Defaults to \c NO
  66. ///
  67. /// Settings this to \c NO will not display the element index for ordered collections.
  68. /// This property only applies to \c NSArray or \c NSOrderedSet and their subclasses.
  69. @property (nonatomic) BOOL hideOrderIndexes;
  70. /// Set this property to provide a custom filter matcher.
  71. ///
  72. /// By default, the collection will filter on the title and subtitle of the row.
  73. /// So if you don't ever call \c configureCell: for example, you will need to set
  74. /// this property so that your filter logic will match how you're setting up the cell.
  75. @property (nonatomic) BOOL (^customFilter)(NSString *filterText, ObjectType element);
  76. /// Get the object in the collection associated with the given row.
  77. /// For dictionaries, this returns the value, not the key.
  78. - (ObjectType)objectForRow:(NSInteger)row;
  79. @end