FLEXTableViewController.h 4.9 KB

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