FLEXTableViewController.h 3.4 KB

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