FLEXTableViewController.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // FLEXTableViewController.h
  3. // FLEX
  4. //
  5. // Created by Tanner on 7/5/19.
  6. // Copyright © 2019 Flipboard. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. @class FLEXScopeCarousel;
  10. typedef CGFloat FLEXDebounceInterval;
  11. /// No delay, all events delivered
  12. extern CGFloat const kFLEXDebounceInstant;
  13. /// Small delay which makes UI seem smoother by avoiding rapid events
  14. extern CGFloat const kFLEXDebounceFast;
  15. /// Slower than Fast, faster than ExpensiveIO
  16. extern CGFloat const kFLEXDebounceForAsyncSearch;
  17. /// The least frequent, at just over once per second; for I/O or other expensive operations
  18. extern CGFloat const kFLEXDebounceForExpensiveIO;
  19. @protocol FLEXSearchResultsUpdating <NSObject>
  20. - (void)updateSearchResults:(NSString *)newText;
  21. @end
  22. @interface FLEXTableViewController : UITableViewController <
  23. UISearchResultsUpdating, UISearchControllerDelegate,
  24. UISearchBarDelegate, FLEXSearchResultsUpdating
  25. >
  26. /// A grouped table view. Inset on iOS 13.
  27. ///
  28. /// Simply calls into initWithStyle:
  29. - (id)init;
  30. /// Defaults to NO.
  31. ///
  32. /// Setting this to YES will initialize the carousel and the view.
  33. @property (nonatomic) BOOL showsCarousel;
  34. /// A horizontally scrolling list with functionality similar to
  35. /// that of a search bar's scope bar. You'd want to use this when
  36. /// you have potentially more than 4 scope options.
  37. @property (nonatomic) FLEXScopeCarousel *carousel;
  38. /// Defaults to NO.
  39. ///
  40. /// Setting this to YES will initialize searchController and the view.
  41. @property (nonatomic) BOOL showsSearchBar;
  42. /// Defaults to NO.
  43. ///
  44. /// Setting this to YES will make the search bar appear whenever the view appears.
  45. /// Otherwise, iOS will only show the search bar when you scroll up.
  46. @property (nonatomic) BOOL showSearchBarInitially;
  47. /// nil unless showsSearchBar is set to YES.
  48. ///
  49. /// self is used as the default search results updater and delegate.
  50. /// The search bar will not dim the background or hide the navigation bar by default.
  51. /// On iOS 11 and up, the search bar will appear in the navigation bar below the title.
  52. @property (nonatomic) UISearchController *searchController;
  53. /// Used to initialize the search controller. Defaults to nil.
  54. @property (nonatomic) UIViewController *searchResultsController;
  55. /// Defaults to "Fast"
  56. ///
  57. /// Determines how often search bar results will be "debounced."
  58. /// Empty query events are always sent instantly. Query events will
  59. /// be sent when the user has not changed the query for this interval.
  60. @property (nonatomic) FLEXDebounceInterval searchBarDebounceInterval;
  61. /// Whether the search bar stays at the top of the view while scrolling.
  62. ///
  63. /// Calls into self.navigationItem.hidesSearchBarWhenScrolling.
  64. /// Do not change self.navigationItem.hidesSearchBarWhenScrolling directly,
  65. /// or it will not be respsected. Use this instead.
  66. /// Defaults to NO.
  67. @property (nonatomic) BOOL pinSearchBar;
  68. /// By default, we will show the search bar's cancel button when
  69. /// search becomes active and hide it when search is dismissed.
  70. ///
  71. /// Do not set the showsCancelButton property on the searchController's
  72. /// searchBar manually. Set this property after turning on showsSearchBar.
  73. ///
  74. /// Does nothing pre-iOS 13, safe to call on any version.
  75. @property (nonatomic) BOOL automaticallyShowsSearchBarCancelButton;
  76. /// If using the scope bar, self.searchController.searchBar.selectedScopeButtonIndex.
  77. /// Otherwise, this is the selected index of the carousel, or NSNotFound if using neither.
  78. @property (nonatomic, readonly) NSInteger selectedScope;
  79. /// self.searchController.searchBar.text
  80. @property (nonatomic, readonly) NSString *searchText;
  81. /// A totally optional delegate to forward search results updater calls to.
  82. /// If a delegate is set, updateSearchResults: is not called on this view controller.
  83. @property (nonatomic, weak ) id<FLEXSearchResultsUpdating> searchResultsUpdater;
  84. /// Subclasses should override to handle search query update events.
  85. ///
  86. /// searchBarDebounceInterval is used to reduce the frequency at which this method is called.
  87. /// This method is also called when the search bar becomes the first responder,
  88. /// and when the selected search bar scope index changes.
  89. - (void)updateSearchResults:(NSString *)newText;
  90. /// Convenient for doing some async processor-intensive searching
  91. /// in the background before updating the UI back on the main queue.
  92. - (void)onBackgroundQueue:(NSArray *(^)(void))backgroundBlock thenOnMainQueue:(void(^)(NSArray *))mainBlock;
  93. @end