mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Add asyncDataFetchingEnabled as parameter of initializer of ASTableView & ASCollectionView
Conflicts: AsyncDisplayKit/ASCollectionView.mm AsyncDisplayKit/Details/ASDataController.mm
This commit is contained in:
@@ -34,6 +34,11 @@
|
|||||||
*/
|
*/
|
||||||
@property (nonatomic, assign) ASRangeTuningParameters rangeTuningParameters;
|
@property (nonatomic, assign) ASRangeTuningParameters rangeTuningParameters;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializer.
|
||||||
|
*/
|
||||||
|
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout asyncDataFetching:(BOOL)asyncDataFetchingEnabled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reload everything from scratch, destroying the working range and all cached nodes.
|
* Reload everything from scratch, destroying the working range and all cached nodes.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -101,6 +101,8 @@ static BOOL _isInterceptedSelector(SEL sel)
|
|||||||
|
|
||||||
BOOL _performingBatchUpdates;
|
BOOL _performingBatchUpdates;
|
||||||
NSMutableArray *_batchUpdateBlocks;
|
NSMutableArray *_batchUpdateBlocks;
|
||||||
|
|
||||||
|
BOOL _asyncDataFetchingEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property (atomic, assign) BOOL asyncDataSourceLocked;
|
@property (atomic, assign) BOOL asyncDataSourceLocked;
|
||||||
@@ -113,6 +115,11 @@ static BOOL _isInterceptedSelector(SEL sel)
|
|||||||
#pragma mark Lifecycle.
|
#pragma mark Lifecycle.
|
||||||
|
|
||||||
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout
|
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout
|
||||||
|
{
|
||||||
|
return [self initWithFrame:frame collectionViewLayout:layout asyncDataFetching:NO];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout asyncDataFetching:(BOOL)asyncDataFetchingEnabled
|
||||||
{
|
{
|
||||||
if (!(self = [super initWithFrame:frame collectionViewLayout:layout]))
|
if (!(self = [super initWithFrame:frame collectionViewLayout:layout]))
|
||||||
return nil;
|
return nil;
|
||||||
@@ -126,13 +133,14 @@ static BOOL _isInterceptedSelector(SEL sel)
|
|||||||
_rangeController.delegate = self;
|
_rangeController.delegate = self;
|
||||||
_rangeController.layoutController = _layoutController;
|
_rangeController.layoutController = _layoutController;
|
||||||
|
|
||||||
_dataController = [[ASDataController alloc] init];
|
_dataController = [[ASDataController alloc] initWithAsyncDataFetching:asyncDataFetchingEnabled];
|
||||||
_dataController.delegate = _rangeController;
|
_dataController.delegate = _rangeController;
|
||||||
_dataController.dataSource = self;
|
_dataController.dataSource = self;
|
||||||
|
|
||||||
_proxyDelegate = [[_ASCollectionViewProxy alloc] initWithTarget:nil interceptor:self];
|
_proxyDelegate = [[_ASCollectionViewProxy alloc] initWithTarget:nil interceptor:self];
|
||||||
super.delegate = (id<UICollectionViewDelegate>)_proxyDelegate;
|
super.delegate = (id<UICollectionViewDelegate>)_proxyDelegate;
|
||||||
|
|
||||||
|
_asyncDataFetchingEnabled = asyncDataFetchingEnabled;
|
||||||
_asyncDataSourceLocked = NO;
|
_asyncDataSourceLocked = NO;
|
||||||
|
|
||||||
_performingBatchUpdates = NO;
|
_performingBatchUpdates = NO;
|
||||||
|
|||||||
@@ -34,6 +34,11 @@
|
|||||||
*/
|
*/
|
||||||
@property (nonatomic, assign) ASRangeTuningParameters rangeTuningParameters;
|
@property (nonatomic, assign) ASRangeTuningParameters rangeTuningParameters;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initializer.
|
||||||
|
*/
|
||||||
|
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style asyncDataFetching:(BOOL)asyncDataFetchingEnabled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reload everything from scratch, destroying the working range and all cached nodes.
|
* Reload everything from scratch, destroying the working range and all cached nodes.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -110,6 +110,8 @@ static BOOL _isInterceptedSelector(SEL sel)
|
|||||||
ASFlowLayoutController *_layoutController;
|
ASFlowLayoutController *_layoutController;
|
||||||
|
|
||||||
ASRangeController *_rangeController;
|
ASRangeController *_rangeController;
|
||||||
|
|
||||||
|
BOOL _asyncDataFetchingEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property (atomic, assign) BOOL asyncDataSouceLocked;
|
@property (atomic, assign) BOOL asyncDataSouceLocked;
|
||||||
@@ -123,6 +125,12 @@ static BOOL _isInterceptedSelector(SEL sel)
|
|||||||
|
|
||||||
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
|
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
|
||||||
{
|
{
|
||||||
|
return [self initWithFrame:frame style:style asyncDataFetching:NO];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style asyncDataFetching:(BOOL)asyncDataFetchingEnabled
|
||||||
|
{
|
||||||
|
|
||||||
if (!(self = [super initWithFrame:frame style:style]))
|
if (!(self = [super initWithFrame:frame style:style]))
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
@@ -132,13 +140,14 @@ static BOOL _isInterceptedSelector(SEL sel)
|
|||||||
_rangeController.layoutController = _layoutController;
|
_rangeController.layoutController = _layoutController;
|
||||||
_rangeController.delegate = self;
|
_rangeController.delegate = self;
|
||||||
|
|
||||||
_dataController = [[ASDataController alloc] init];
|
_dataController = [[ASDataController alloc] initWithAsyncDataFetching:asyncDataFetchingEnabled];
|
||||||
_dataController.dataSource = self;
|
_dataController.dataSource = self;
|
||||||
_dataController.delegate = _rangeController;
|
_dataController.delegate = _rangeController;
|
||||||
|
|
||||||
_proxyDelegate = [[_ASTableViewProxy alloc] initWithTarget:nil interceptor:self];
|
_proxyDelegate = [[_ASTableViewProxy alloc] initWithTarget:nil interceptor:self];
|
||||||
super.delegate = (id<UITableViewDelegate>)_proxyDelegate;
|
super.delegate = (id<UITableViewDelegate>)_proxyDelegate;
|
||||||
|
|
||||||
|
_asyncDataFetchingEnabled = asyncDataFetchingEnabled;
|
||||||
_asyncDataSouceLocked = NO;
|
_asyncDataSouceLocked = NO;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
@@ -168,6 +177,9 @@ static BOOL _isInterceptedSelector(SEL sel)
|
|||||||
_proxyDataSource = nil;
|
_proxyDataSource = nil;
|
||||||
super.dataSource = nil;
|
super.dataSource = nil;
|
||||||
} else {
|
} else {
|
||||||
|
ASDisplayNodeAssert(!_asyncDataFetchingEnabled || ([asyncDataSource respondsToSelector:@selector(tableViewLockDataSourceForDataUpdating:)] &&
|
||||||
|
[asyncDataSource respondsToSelector:@selector(tableViewUnlockDataSourceForDataUpdating:)]),
|
||||||
|
@"The asyncDataSource need to implements \"tableViewLockDataSourceForDataUpdating\" and \"tableViewUnlockDataSourceForDataUpdating\" to handle data fetching in async mode.");
|
||||||
_asyncDataSource = asyncDataSource;
|
_asyncDataSource = asyncDataSource;
|
||||||
_proxyDataSource = [[_ASTableViewProxy alloc] initWithTarget:_asyncDataSource interceptor:self];
|
_proxyDataSource = [[_ASTableViewProxy alloc] initWithTarget:_asyncDataSource interceptor:self];
|
||||||
super.dataSource = (id<UITableViewDataSource>)_proxyDataSource;
|
super.dataSource = (id<UITableViewDataSource>)_proxyDataSource;
|
||||||
|
|||||||
@@ -119,6 +119,11 @@ typedef NSUInteger ASDataControllerAnimationOptions;
|
|||||||
*/
|
*/
|
||||||
@property (nonatomic, weak) id<ASDataControllerDelegate> delegate;
|
@property (nonatomic, weak) id<ASDataControllerDelegate> delegate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Designated iniailizer.
|
||||||
|
*/
|
||||||
|
- (instancetype)initWithAsyncDataFetching:(BOOL)asyncDataFetchingEnabled;
|
||||||
|
|
||||||
/** @name Initial loading */
|
/** @name Initial loading */
|
||||||
|
|
||||||
- (void)initialDataLoadingWithAnimationOption:(ASDataControllerAnimationOptions)animationOption;
|
- (void)initialDataLoadingWithAnimationOption:(ASDataControllerAnimationOptions)animationOption;
|
||||||
|
|||||||
@@ -12,11 +12,18 @@
|
|||||||
|
|
||||||
#ifdef ENABLE_ASYNC_DATA_FETCHING
|
#ifdef ENABLE_ASYNC_DATA_FETCHING
|
||||||
#define BEGIN_DATA_FETCHING \
|
#define BEGIN_DATA_FETCHING \
|
||||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ \
|
dispatch_block_t block = ^{
|
||||||
[_dataSource dataControllerLockDataSourceForDataUpdating];
|
|
||||||
#define END_DATA_FETCHING \
|
#define END_DATA_FETCHING \
|
||||||
[_dataSource dataControllerUnlockDataSourceForDataUpdating]; \
|
}; \
|
||||||
});
|
if (_asyncDataFetchingEnabled) { \
|
||||||
|
[_dataSource dataControllerLockDataSourceForDataUpdating]; \
|
||||||
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ \
|
||||||
|
block(); \
|
||||||
|
[_dataSource dataControllerUnlockDataSourceForDataUpdating]; \
|
||||||
|
}); \
|
||||||
|
} else { \
|
||||||
|
block(); \
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
#define BEGIN_DATA_FETCHING
|
#define BEGIN_DATA_FETCHING
|
||||||
#define END_DATA_FETCHING
|
#define END_DATA_FETCHING
|
||||||
@@ -73,6 +80,7 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
|
|||||||
@interface ASDataController () {
|
@interface ASDataController () {
|
||||||
NSMutableArray *_nodes;
|
NSMutableArray *_nodes;
|
||||||
NSMutableArray *_pendingBlocks;
|
NSMutableArray *_pendingBlocks;
|
||||||
|
BOOL _asyncDataFetchingEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property (atomic, assign) NSUInteger batchUpdateCounter;
|
@property (atomic, assign) NSUInteger batchUpdateCounter;
|
||||||
@@ -81,11 +89,12 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
|
|||||||
|
|
||||||
@implementation ASDataController
|
@implementation ASDataController
|
||||||
|
|
||||||
- (instancetype)init {
|
- (instancetype)initWithAsyncDataFetching:(BOOL)asyncDataFetchingEnabled {
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
_nodes = [NSMutableArray array];
|
_nodes = [NSMutableArray array];
|
||||||
_pendingBlocks = [NSMutableArray array];
|
_pendingBlocks = [NSMutableArray array];
|
||||||
_batchUpdateCounter = 0;
|
_batchUpdateCounter = 0;
|
||||||
|
_asyncDataFetchingEnabled = asyncDataFetchingEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
@@ -143,8 +152,7 @@ static void *kASSizingQueueContext = &kASSizingQueueContext;
|
|||||||
|
|
||||||
#pragma mark - Initial Data Loading
|
#pragma mark - Initial Data Loading
|
||||||
|
|
||||||
- (void)initialDataLoadingWithAnimationOption:(ASDataControllerAnimationOptions)animationOption
|
- (void)initialDataLoadingWithAnimationOption:(ASDataControllerAnimationOptions)animationOption {
|
||||||
{
|
|
||||||
BEGIN_DATA_FETCHING
|
BEGIN_DATA_FETCHING
|
||||||
|
|
||||||
NSMutableArray *indexPaths = [NSMutableArray array];
|
NSMutableArray *indexPaths = [NSMutableArray array];
|
||||||
|
|||||||
Reference in New Issue
Block a user