FLEXTableViewController.h 6.0 KB

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