[Batch Fetching] Add ASBatchFetchingDelegate (#281)

* Add ASBatchFetchingDelegate
- In addition to checking remaining leading screens, ASBatchFetching now also calculates a remaining time and consults its delegate if needed.
- The delegate can override the decision of ASBatchFetching, for example based on remaining time and average time of past batch requests.

* Fix up tests

* Update CHANGELOG
This commit is contained in:
Huy Nguyen
2017-05-17 13:26:30 +01:00
committed by GitHub
parent 432018cfdc
commit 8c45eaefce
12 changed files with 160 additions and 32 deletions

View File

@@ -21,13 +21,17 @@
ASDISPLAYNODE_EXTERN_C_BEGIN
NS_ASSUME_NONNULL_BEGIN
@class ASBatchContext;
@protocol ASBatchFetchingDelegate;
@protocol ASBatchFetchingScrollView <NSObject>
- (BOOL)canBatchFetch;
- (ASBatchContext *)batchContext;
- (CGFloat)leadingScreensForBatching;
- (nullable id<ASBatchFetchingDelegate>)batchFetchingDelegate;
@end
@@ -39,9 +43,14 @@ ASDISPLAYNODE_EXTERN_C_BEGIN
@param scrollDirection The current scrolling direction of the scroll view.
@param scrollableDirections The possible scrolling directions of the scroll view.
@param contentOffset The offset that the scrollview will scroll to.
@param velocity The velocity of the scroll view (in points) at the moment the touch was released.
@return Whether or not the current state should proceed with batch fetching.
*/
BOOL ASDisplayShouldFetchBatchForScrollView(UIScrollView<ASBatchFetchingScrollView> *scrollView, ASScrollDirection scrollDirection, ASScrollDirection scrollableDirections, CGPoint contentOffset);
BOOL ASDisplayShouldFetchBatchForScrollView(UIScrollView<ASBatchFetchingScrollView> *scrollView,
ASScrollDirection scrollDirection,
ASScrollDirection scrollableDirections,
CGPoint contentOffset,
CGPoint velocity);
/**
@@ -54,6 +63,8 @@ BOOL ASDisplayShouldFetchBatchForScrollView(UIScrollView<ASBatchFetchingScrollVi
@param targetOffset The offset that the scrollview will scroll to.
@param leadingScreens How many screens in the remaining distance will trigger batch fetching.
@param visible Whether the view is visible or not.
@param velocity The velocity of the scroll view (in points) at the moment the touch was released.
@param delegate The delegate to be consulted if needed.
@return Whether or not the current state should proceed with batch fetching.
@discussion This method is broken into a category for unit testing purposes and should be used with the ASTableView and
* ASCollectionView batch fetching API.
@@ -65,6 +76,9 @@ extern BOOL ASDisplayShouldFetchBatchForContext(ASBatchContext *context,
CGSize contentSize,
CGPoint targetOffset,
CGFloat leadingScreens,
BOOL visible);
BOOL visible,
CGPoint velocity,
_Nullable id<ASBatchFetchingDelegate> delegate);
NS_ASSUME_NONNULL_END
ASDISPLAYNODE_EXTERN_C_END