mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-06 14:25:04 +00:00
This diff resolves all known consistency issues with ASTableView and ASCollectionView. It includes significantly more aggressive thrash-testing in ASTableViewStressTest, which now passes on a variety of device and simulator configurations. It also updates the unit tests run on every commit to ensure any regression is caught quickly. A few of the salient changes in this diff: - ASTableView now uses Rene's ASCollectionViewLayoutController, and actually uses a UICollectionViewFlowLayout without any UICollectionView. This resolves an issue where ASFlowLayoutController was generating slightly out-of-bounds indicies when programmatically scrolling past the end of the table content. Because the custom implementation is likely faster, I will revisit this later with profiling and possibly returning to the custom impl. - There is now a second copy of the _nodes array maintained by ASDataController. It shares the same node instances, but this does add some overhead to manipulating the arrays. I've filed a task to follow up with optimization, as there are several great opportunities to make it faster. However, I don't believe the overhead is a significant issue, and it does guarantee correctness in even the toughest app usage scenarios. - ASDataController no longer supports calling its delegate /before/ edit operations. No other class was relying on this behavior, and it would be unusual for an app developer to use ASDataController directly. However, it is possible that someone with a custom view that integrates with ASDataController and ASRangeController could be affected by this. - Further cleanup of organization, naming, additional comments, reduced code length wherever possible. Overall, significantly more accessible to a new reader.
111 lines
3.7 KiB
Objective-C
111 lines
3.7 KiB
Objective-C
/* Copyright (c) 2014-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
#import <AsyncDisplayKit/ASCellNode.h>
|
|
#import <AsyncDisplayKit/ASDataController.h>
|
|
#import <AsyncDisplayKit/ASFlowLayoutController.h>
|
|
#import <AsyncDisplayKit/ASLayoutController.h>
|
|
|
|
|
|
@protocol ASRangeControllerDelegate;
|
|
|
|
/**
|
|
* Working range controller.
|
|
*
|
|
* Used internally by ASTableView and ASCollectionView. It is paired with ASDataController.
|
|
* It is designed to support custom scrolling containers as well. Observes the visible range, maintains
|
|
* "working ranges" to trigger network calls and rendering, and is responsible for driving asynchronous layout of cells.
|
|
* This includes cancelling those asynchronous operations as cells fall outside of the working ranges.
|
|
*/
|
|
@interface ASRangeController : ASDealloc2MainObject <ASDataControllerDelegate>
|
|
|
|
/**
|
|
* Notify the range controller that the visible range has been updated.
|
|
* This is the primary input call that drives updating the working ranges, and triggering their actions.
|
|
*
|
|
* @see [ASRangeControllerDelegate rangeControllerVisibleNodeIndexPaths:]
|
|
*/
|
|
- (void)visibleNodeIndexPathsDidChangeWithScrollDirection:(ASScrollDirection)scrollDirection;
|
|
|
|
/**
|
|
* Add the sized node for `indexPath` as a subview of `contentView`.
|
|
*
|
|
* @param contentView UIView to add a (sized) node's view to.
|
|
*
|
|
* @param node The ASCellNode to be added.
|
|
*/
|
|
- (void)configureContentView:(UIView *)contentView forCellNode:(ASCellNode *)node;
|
|
|
|
/**
|
|
* Delegate and ultimate data source. Must not be nil.
|
|
*/
|
|
@property (nonatomic, weak) id<ASRangeControllerDelegate> delegate;
|
|
|
|
@property (nonatomic, strong) id<ASLayoutController> layoutController;
|
|
|
|
@end
|
|
|
|
|
|
/**
|
|
* <ASRangeController> delegate. For example, <ASTableView>.
|
|
*/
|
|
@protocol ASRangeControllerDelegate <NSObject>
|
|
|
|
/**
|
|
* @param rangeController Sender.
|
|
*
|
|
* @returns an array of index paths corresponding to the nodes currently visible onscreen (i.e., the visible range).
|
|
*/
|
|
- (NSArray *)rangeControllerVisibleNodeIndexPaths:(ASRangeController *)rangeController;
|
|
|
|
/**
|
|
* @param rangeController Sender.
|
|
*
|
|
* @returns the receiver's viewport size (i.e., the screen space occupied by the visible range).
|
|
*/
|
|
- (CGSize)rangeControllerViewportSize:(ASRangeController *)rangeController;
|
|
|
|
/**
|
|
* Begin updates.
|
|
*/
|
|
- (void)rangeControllerBeginUpdates:(ASRangeController *)rangeController;
|
|
|
|
/**
|
|
* End updates.
|
|
*/
|
|
- (void)rangeControllerEndUpdates:(ASRangeController * )rangeController completion:(void (^)(BOOL))completion ;
|
|
|
|
/**
|
|
* Fetch nodes at specific index paths.
|
|
*/
|
|
- (NSArray *)rangeController:(ASRangeController *)rangeController nodesAtIndexPaths:(NSArray *)indexPaths;
|
|
|
|
/**
|
|
* Called for nodes insertion.
|
|
*/
|
|
- (void)rangeController:(ASRangeController *)rangeController didInsertNodesAtIndexPaths:(NSArray *)indexPaths withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions;
|
|
|
|
/**
|
|
* Called for nodes deletion.
|
|
*/
|
|
- (void)rangeController:(ASRangeController *)rangeController didDeleteNodesAtIndexPaths:(NSArray *)indexPaths withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions;
|
|
|
|
/**
|
|
* Called for section insertion.
|
|
*/
|
|
- (void)rangeController:(ASRangeController *)rangeController didInsertSectionsAtIndexSet:(NSIndexSet *)indexSet withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions;
|
|
|
|
/**
|
|
* Called for section deletion.
|
|
*/
|
|
- (void)rangeController:(ASRangeController *)rangeController didDeleteSectionsAtIndexSet:(NSIndexSet *)indexSet withAnimationOptions:(ASDataControllerAnimationOptions)animationOptions;
|
|
|
|
@end
|