FLEXTableViewController.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // FLEXTableViewController.h
  3. // FLEX
  4. //
  5. // Created by Tanner on 7/5/19.
  6. // Copyright © 2020 FLEX Team. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. #import "FLEXTableView.h"
  10. @class FLEXScopeCarousel, FLEXWindow, FLEXTableViewSection;
  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. /// A method to handle search query update events.
  22. ///
  23. /// \c searchBarDebounceInterval is used to reduce the frequency at which this
  24. /// method is called. This method is also called when the search bar becomes
  25. /// the first responder, and when the selected search bar scope index changes.
  26. - (void)updateSearchResults:(NSString *)newText;
  27. @end
  28. @interface FLEXTableViewController : UITableViewController <
  29. UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate
  30. >
  31. /// A grouped table view. Inset on iOS 13.
  32. ///
  33. /// Simply calls into \c initWithStyle:
  34. - (id)init;
  35. /// Subclasses may override to configure the controller before \c viewDidLoad:
  36. - (id)initWithStyle:(UITableViewStyle)style;
  37. @property (nonatomic) FLEXTableView *tableView;
  38. /// If your subclass conforms to \c FLEXSearchResultsUpdating
  39. /// then this property is assigned to \c self automatically.
  40. ///
  41. /// Setting \c filterDelegate will also set this property to that object.
  42. @property (nonatomic, weak) id<FLEXSearchResultsUpdating> searchDelegate;
  43. /// Defaults to NO.
  44. ///
  45. /// Setting this to YES will initialize the carousel and the view.
  46. @property (nonatomic) BOOL showsCarousel;
  47. /// A horizontally scrolling list with functionality similar to
  48. /// that of a search bar's scope bar. You'd want to use this when
  49. /// you have potentially more than 4 scope options.
  50. @property (nonatomic) FLEXScopeCarousel *carousel;
  51. /// Defaults to NO.
  52. ///
  53. /// Setting this to YES will initialize searchController and the view.
  54. @property (nonatomic) BOOL showsSearchBar;
  55. /// Defaults to NO.
  56. ///
  57. /// Setting this to YES will make the search bar appear whenever the view appears.
  58. /// Otherwise, iOS will only show the search bar when you scroll up.
  59. @property (nonatomic) BOOL showSearchBarInitially;
  60. /// nil unless showsSearchBar is set to YES.
  61. ///
  62. /// self is used as the default search results updater and delegate.
  63. /// The search bar will not dim the background or hide the navigation bar by default.
  64. /// On iOS 11 and up, the search bar will appear in the navigation bar below the title.
  65. @property (nonatomic) UISearchController *searchController;
  66. /// Used to initialize the search controller. Defaults to nil.
  67. @property (nonatomic) UIViewController *searchResultsController;
  68. /// Defaults to "Fast"
  69. ///
  70. /// Determines how often search bar results will be "debounced."
  71. /// Empty query events are always sent instantly. Query events will
  72. /// be sent when the user has not changed the query for this interval.
  73. @property (nonatomic) FLEXDebounceInterval searchBarDebounceInterval;
  74. /// Whether the search bar stays at the top of the view while scrolling.
  75. ///
  76. /// Calls into self.navigationItem.hidesSearchBarWhenScrolling.
  77. /// Do not change self.navigationItem.hidesSearchBarWhenScrolling directly,
  78. /// or it will not be respsected. Use this instead.
  79. /// Defaults to NO.
  80. @property (nonatomic) BOOL pinSearchBar;
  81. /// By default, we will show the search bar's cancel button when
  82. /// search becomes active and hide it when search is dismissed.
  83. ///
  84. /// Do not set the showsCancelButton property on the searchController's
  85. /// searchBar manually. Set this property after turning on showsSearchBar.
  86. ///
  87. /// Does nothing pre-iOS 13, safe to call on any version.
  88. @property (nonatomic) BOOL automaticallyShowsSearchBarCancelButton;
  89. /// If using the scope bar, self.searchController.searchBar.selectedScopeButtonIndex.
  90. /// Otherwise, this is the selected index of the carousel, or NSNotFound if using neither.
  91. @property (nonatomic) NSInteger selectedScope;
  92. /// self.searchController.searchBar.text
  93. @property (nonatomic, readonly, copy) NSString *searchText;
  94. /// A totally optional delegate to forward search results updater calls to.
  95. /// If a delegate is set, updateSearchResults: is not called on this view controller.
  96. @property (nonatomic, weak) id<FLEXSearchResultsUpdating> searchResultsUpdater;
  97. /// self.view.window as a \c FLEXWindow
  98. @property (nonatomic, readonly) FLEXWindow *window;
  99. /// Convenient for doing some async processor-intensive searching
  100. /// in the background before updating the UI back on the main queue.
  101. - (void)onBackgroundQueue:(NSArray *(^)(void))backgroundBlock thenOnMainQueue:(void(^)(NSArray *))mainBlock;
  102. /// Adds up to 3 additional items to the toolbar in right-to-left order.
  103. ///
  104. /// That is, the first item in the given array will be the rightmost item behind
  105. /// any existing toolbar items. By default, buttons for bookmarks and tabs are shown.
  106. ///
  107. /// If you wish to have more control over how the buttons are arranged or which
  108. /// buttons are displayed, you can access the properties for the pre-existing
  109. /// toolbar items directly and manually set \c self.toolbarItems by overriding
  110. /// the \c setupToolbarItems method below.
  111. - (void)addToolbarItems:(NSArray<UIBarButtonItem *> *)items;
  112. /// Subclasses may override. You should not need to call this method directly.
  113. - (void)setupToolbarItems;
  114. @property (nonatomic, readonly) UIBarButtonItem *shareToolbarItem;
  115. @property (nonatomic, readonly) UIBarButtonItem *bookmarksToolbarItem;
  116. @property (nonatomic, readonly) UIBarButtonItem *openTabsToolbarItem;
  117. /// Whether or not to display the "share" icon in the middle of the toolbar. NO by default.
  118. ///
  119. /// Turning this on after you have added custom toolbar items will
  120. /// push off the leftmost toolbar item and shift the others leftward.
  121. @property (nonatomic) BOOL showsShareToolbarItem;
  122. /// Called when the share button is pressed.
  123. /// Default implementation does nothign. Subclasses may override.
  124. - (void)shareButtonPressed:(UIBarButtonItem *)sender;
  125. /// Subclasses may call this to opt-out of all toolbar related behavior.
  126. /// This is necessary if you want to disable the gesture which reveals the toolbar.
  127. - (void)disableToolbar;
  128. @end