FLEXTableViewController.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. @interface FLEXTableViewController : UITableViewController <UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate>
  20. /// A grouped table view. Inset on iOS 13.
  21. ///
  22. /// Simply calls into initWithStyle:
  23. - (id)init;
  24. /// Defaults to NO.
  25. ///
  26. /// Setting this to YES will initialize the carousel and the view.
  27. @property (nonatomic) BOOL showsCarousel;
  28. /// A horizontally scrolling list with functionality similar to
  29. /// that of a search bar's scope bar. You'd want to use this when
  30. /// you have potentially more than 4 scope options.
  31. @property (nonatomic) FLEXScopeCarousel *carousel;
  32. /// Defaults to NO.
  33. ///
  34. /// Setting this to YES will initialize searchController and the view.
  35. @property (nonatomic) BOOL showsSearchBar;
  36. /// nil unless showsSearchBar is set to YES.
  37. ///
  38. /// self is used as the default search results updater and delegate.
  39. /// Make sure your subclass conforms to UISearchControllerDelegate.
  40. /// The search bar will not dim the background or hide the navigation bar by default.
  41. /// On iOS 11 and up, the search bar will appear in the navigation bar below the title.
  42. @property (nonatomic) UISearchController *searchController;
  43. /// Used to initialize the search controller. Defaults to nil.
  44. @property (nonatomic) UIViewController *searchResultsController;
  45. /// Defaults to "Fast"
  46. ///
  47. /// Determines how often search bar results will be "debounced."
  48. /// Empty query events are always sent instantly. Query events will
  49. /// be sent when the user has not changed the query for this interval.
  50. @property (nonatomic) FLEXDebounceInterval searchBarDebounceInterval;
  51. /// Whether the search bar stays at the top of the view while scrolling.
  52. ///
  53. /// Calls into self.navigationItem.hidesSearchBarWhenScrolling.
  54. /// Do not change self.navigationItem.hidesSearchBarWhenScrolling directly,
  55. /// or it will not be respsected. Use this instead.
  56. /// Defaults to NO.
  57. @property (nonatomic) BOOL pinSearchBar;
  58. /// By default, we will show the search bar's cancel button when
  59. /// search becomes active and hide it when search is dismissed.
  60. ///
  61. /// Do not set the showsCancelButton property on the searchController's
  62. /// searchBar manually.
  63. @property (nonatomic) BOOL automaticallyShowsSearchBarCancelButton;
  64. /// If using the scope bar, self.searchController.searchBar.selectedScopeButtonIndex.
  65. /// Otherwise, this is the selected index of the carousel, or NSNotFound if using neither.
  66. @property (nonatomic, readonly) NSInteger selectedScope;
  67. /// self.searchController.searchBar.text
  68. @property (nonatomic, readonly) NSString *searchText;
  69. /// Subclasses should override to handle search query update events.
  70. ///
  71. /// searchBarDebounceInterval is used to reduce the frequency at which this method is called.
  72. /// This method is also called when the search bar becomes the first responder,
  73. /// and when the selected search bar scope index changes.
  74. - (void)updateSearchResults:(NSString *)newText;
  75. /// Convenient for doing some async processor-intensive searching
  76. /// in the background before updating the UI back on the main queue.
  77. - (void)onBackgroundQueue:(NSArray *(^)(void))backgroundBlock thenOnMainQueue:(void(^)(NSArray *))mainBlock;
  78. @end