FLEXTableViewController.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. typedef CGFloat FLEXDebounceInterval;
  10. /// No delay, all events delivered
  11. extern CGFloat const kFLEXDebounceInstant;
  12. /// Small delay which makes UI seem smoother by avoiding rapid events
  13. extern CGFloat const kFLEXDebounceFast;
  14. /// Slower than Fast, faster than ExpensiveIO
  15. extern CGFloat const kFLEXDebounceForAsyncSearch;
  16. /// The least frequent, at just over once per second; for I/O or other expensive operations
  17. extern CGFloat const kFLEXDebounceForExpensiveIO;
  18. @interface FLEXTableViewController : UITableViewController <UISearchResultsUpdating, UISearchControllerDelegate>
  19. /// A grouped table view. Inset on iOS 13.
  20. ///
  21. /// Simply calls into initWithStyle:
  22. - (id)init;
  23. /// Defaults to NO.
  24. ///
  25. /// Setting this to YES will initialize searchController.
  26. @property (nonatomic) BOOL showsSearchBar;
  27. /// nil unless showsSearchBar is set to YES.
  28. ///
  29. /// self is used as the default search results updater and delegate.
  30. /// Make sure your subclass conforms to UISearchControllerDelegate.
  31. /// The search bar will not dim the background or hide the navigation bar by default.
  32. /// On iOS 11 and up, the search bar will appear in the navigation bar below the title.
  33. @property (nonatomic) UISearchController *searchController;
  34. /// Used to initialize the search controller. Defaults to nil.
  35. @property (nonatomic) UIViewController *searchResultsController;
  36. /// Defaults to "Fast"
  37. ///
  38. /// Determines how often search bar results will be "debounced."
  39. /// Empty query events are always sent instantly. Query events will
  40. /// be sent when the user has not changed the query for this interval.
  41. @property (nonatomic) FLEXDebounceInterval searchBarDebounceInterval;
  42. /// Whether the search bar stays at the top of the view while scrolling.
  43. ///
  44. /// Calls into self.navigationItem.hidesSearchBarWhenScrolling.
  45. /// Do not change self.navigationItem.hidesSearchBarWhenScrolling directly,
  46. /// or it will not be respsected. Use this instead.
  47. /// Defaults to NO.
  48. @property (nonatomic) BOOL pinSearchBar;
  49. /// By default, we will show the search bar's cancel button when
  50. /// search becomes active and hide it when search is dismissed.
  51. ///
  52. /// Do not set the showsCancelButton property on the searchController's
  53. /// searchBar manually.
  54. @property (nonatomic) BOOL automaticallyShowsSearchBarCancelButton;
  55. /// self.searchController.searchBar.selectedScopeButtonIndex
  56. @property (nonatomic, readonly) NSInteger selectedScope;
  57. /// self.searchController.searchBar.text
  58. @property (nonatomic, readonly) NSString *searchText;
  59. /// Subclasses should override to handle search query update events.
  60. ///
  61. /// searchBarDebounceInterval is used to reduce the frequency at which this method is called.
  62. /// This method is also called when the search bar becomes the first responder,
  63. /// and when the selected search bar scope index changes.
  64. - (void)updateSearchResults:(NSString *)newText;
  65. /// Convenient for doing some async processor-intensive searching
  66. /// in the background before updating the UI back on the main queue.
  67. - (void)onBackgroundQueue:(NSArray *(^)())backgroundBlock thenOnMainQueue:(void(^)(NSArray *))mainBlock;
  68. @end