FLEXTableViewController.h 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. /// Defaults to NO.
  37. ///
  38. /// Setting this to YES will make the search bar appear whenever the view appears.
  39. /// Otherwise, iOS will only show the search bar when you scroll up.
  40. @property (nonatomic) BOOL showSearchBarInitially;
  41. /// nil unless showsSearchBar is set to YES.
  42. ///
  43. /// self is used as the default search results updater and delegate.
  44. /// Make sure your subclass conforms to UISearchControllerDelegate.
  45. /// The search bar will not dim the background or hide the navigation bar by default.
  46. /// On iOS 11 and up, the search bar will appear in the navigation bar below the title.
  47. @property (nonatomic) UISearchController *searchController;
  48. /// Used to initialize the search controller. Defaults to nil.
  49. @property (nonatomic) UIViewController *searchResultsController;
  50. /// Defaults to "Fast"
  51. ///
  52. /// Determines how often search bar results will be "debounced."
  53. /// Empty query events are always sent instantly. Query events will
  54. /// be sent when the user has not changed the query for this interval.
  55. @property (nonatomic) FLEXDebounceInterval searchBarDebounceInterval;
  56. /// Whether the search bar stays at the top of the view while scrolling.
  57. ///
  58. /// Calls into self.navigationItem.hidesSearchBarWhenScrolling.
  59. /// Do not change self.navigationItem.hidesSearchBarWhenScrolling directly,
  60. /// or it will not be respsected. Use this instead.
  61. /// Defaults to NO.
  62. @property (nonatomic) BOOL pinSearchBar;
  63. /// By default, we will show the search bar's cancel button when
  64. /// search becomes active and hide it when search is dismissed.
  65. ///
  66. /// Do not set the showsCancelButton property on the searchController's
  67. /// searchBar manually. Set this property after turning on showsSearchBar.
  68. ///
  69. /// Does nothing pre-iOS 13, safe to call on any version.
  70. @property (nonatomic) BOOL automaticallyShowsSearchBarCancelButton;
  71. /// If using the scope bar, self.searchController.searchBar.selectedScopeButtonIndex.
  72. /// Otherwise, this is the selected index of the carousel, or NSNotFound if using neither.
  73. @property (nonatomic, readonly) NSInteger selectedScope;
  74. /// self.searchController.searchBar.text
  75. @property (nonatomic, readonly) NSString *searchText;
  76. /// Subclasses should override to handle search query update events.
  77. ///
  78. /// searchBarDebounceInterval is used to reduce the frequency at which this method is called.
  79. /// This method is also called when the search bar becomes the first responder,
  80. /// and when the selected search bar scope index changes.
  81. - (void)updateSearchResults:(NSString *)newText;
  82. /// Convenient for doing some async processor-intensive searching
  83. /// in the background before updating the UI back on the main queue.
  84. - (void)onBackgroundQueue:(NSArray *(^)(void))backgroundBlock thenOnMainQueue:(void(^)(NSArray *))mainBlock;
  85. @end