mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Support custom working-range logic.
This commit is contained in:
@@ -34,6 +34,13 @@
|
|||||||
*/
|
*/
|
||||||
@property (nonatomic, assign) ASRangeTuningParameters rangeTuningParameters;
|
@property (nonatomic, assign) ASRangeTuningParameters rangeTuningParameters;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @abstract An optional block which can perform custom calculation for working range.
|
||||||
|
*
|
||||||
|
* @discussion Can be used to provide custom working range logic for custom layouts.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, assign) asrangecontroller_working_range_calculation_block_t workingRangeCalculationBlock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reload everything from scratch, destroying the working range and all cached nodes.
|
* Reload everything from scratch, destroying the working range and all cached nodes.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -165,6 +165,16 @@ static BOOL _isInterceptedSelector(SEL sel)
|
|||||||
_rangeController.tuningParameters = tuningParameters;
|
_rangeController.tuningParameters = tuningParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (asrangecontroller_working_range_calculation_block_t)workingRangeCalculationBlock
|
||||||
|
{
|
||||||
|
return _rangeController.workingRangeCalculationBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setWorkingRangeCalculationBlock:(asrangecontroller_working_range_calculation_block_t)workingRangeCalculationBlock
|
||||||
|
{
|
||||||
|
_rangeController.workingRangeCalculationBlock = workingRangeCalculationBlock;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)appendNodesWithIndexPaths:(NSArray *)indexPaths
|
- (void)appendNodesWithIndexPaths:(NSArray *)indexPaths
|
||||||
{
|
{
|
||||||
[_rangeController appendNodesWithIndexPaths:indexPaths];
|
[_rangeController appendNodesWithIndexPaths:indexPaths];
|
||||||
|
|||||||
@@ -16,6 +16,13 @@ typedef struct {
|
|||||||
CGFloat leadingBufferScreenfuls;
|
CGFloat leadingBufferScreenfuls;
|
||||||
} ASRangeTuningParameters;
|
} ASRangeTuningParameters;
|
||||||
|
|
||||||
|
typedef NS_ENUM(NSInteger, ASScrollDirection) {
|
||||||
|
ASScrollDirectionBackward,
|
||||||
|
ASScrollDirectionForward,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef NSRange (^asrangecontroller_working_range_calculation_block_t)(ASRangeTuningParameters params, ASScrollDirection scrollDirection, NSRange visibleRange, NSArray *nodeSizes, CGSize viewport);
|
||||||
|
|
||||||
@protocol ASRangeControllerDelegate;
|
@protocol ASRangeControllerDelegate;
|
||||||
|
|
||||||
|
|
||||||
@@ -99,6 +106,13 @@ typedef struct {
|
|||||||
*/
|
*/
|
||||||
@property (nonatomic, assign) ASRangeTuningParameters tuningParameters;
|
@property (nonatomic, assign) ASRangeTuningParameters tuningParameters;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @abstract An optional block which can perform custom calculation for working range.
|
||||||
|
*
|
||||||
|
* @discussion Can be used to provide custom working range logic for custom layouts.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readwrite, copy) asrangecontroller_working_range_calculation_block_t workingRangeCalculationBlock;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,11 +13,6 @@
|
|||||||
#import "ASDisplayNodeInternal.h"
|
#import "ASDisplayNodeInternal.h"
|
||||||
#import "ASRangeControllerInternal.h"
|
#import "ASRangeControllerInternal.h"
|
||||||
|
|
||||||
typedef NS_ENUM(NSInteger, ASScrollDirection) {
|
|
||||||
ASScrollDirectionBackward,
|
|
||||||
ASScrollDirectionForward,
|
|
||||||
};
|
|
||||||
|
|
||||||
@interface ASRangeController () {
|
@interface ASRangeController () {
|
||||||
// index path -> node mapping
|
// index path -> node mapping
|
||||||
NSMutableDictionary *_nodes;
|
NSMutableDictionary *_nodes;
|
||||||
@@ -472,11 +467,21 @@ static NSRange ASCalculateWorkingRange(ASRangeTuningParameters params, ASScrollD
|
|||||||
|
|
||||||
- (void)recalculateWorkingRange
|
- (void)recalculateWorkingRange
|
||||||
{
|
{
|
||||||
NSRange workingRange = ASCalculateWorkingRange(_tuningParameters,
|
NSRange workingRange;
|
||||||
|
if (self.workingRangeCalculationBlock != NULL) {
|
||||||
|
workingRange = self.workingRangeCalculationBlock(_tuningParameters,
|
||||||
_scrollDirection,
|
_scrollDirection,
|
||||||
_visibleRange,
|
_visibleRange,
|
||||||
_nodeSizes,
|
_nodeSizes,
|
||||||
[_delegate rangeControllerViewportSize:self]);
|
[_delegate rangeControllerViewportSize:self]);
|
||||||
|
} else {
|
||||||
|
workingRange = ASCalculateWorkingRange(_tuningParameters,
|
||||||
|
_scrollDirection,
|
||||||
|
_visibleRange,
|
||||||
|
_nodeSizes,
|
||||||
|
[_delegate rangeControllerViewportSize:self]);
|
||||||
|
}
|
||||||
|
|
||||||
[self setWorkingRange:workingRange];
|
[self setWorkingRange:workingRange];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user