mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Added selection API to ASTableNode and ASCollectionNode (#2453)
* Added selection API to ASTableNode and ASCollectionNode (#2450) * Updated test case to use collectionNode instead of collectionView for the selection tests. * Fixed typos. Added asserts for main thread. Updated ASCollectionViewTests for multiple selections for nodes. * Added assigns to the different properties.
This commit is contained in:
@@ -24,7 +24,11 @@
|
||||
@interface _ASTablePendingState : NSObject
|
||||
@property (weak, nonatomic) id <ASTableDelegate> delegate;
|
||||
@property (weak, nonatomic) id <ASTableDataSource> dataSource;
|
||||
@property (assign, nonatomic) ASLayoutRangeMode rangeMode;
|
||||
@property (nonatomic, assign) ASLayoutRangeMode rangeMode;
|
||||
@property (nonatomic, assign) BOOL allowsSelection;
|
||||
@property (nonatomic, assign) BOOL allowsSelectionDuringEditing;
|
||||
@property (nonatomic, assign) BOOL allowsMultipleSelection;
|
||||
@property (nonatomic, assign) BOOL allowsMultipleSelectionDuringEditing;
|
||||
@end
|
||||
|
||||
@implementation _ASTablePendingState
|
||||
@@ -33,6 +37,10 @@
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_rangeMode = ASLayoutRangeModeCount;
|
||||
_allowsSelection = YES;
|
||||
_allowsSelectionDuringEditing = NO;
|
||||
_allowsMultipleSelection = NO;
|
||||
_allowsMultipleSelectionDuringEditing = NO;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -104,6 +112,10 @@
|
||||
self.pendingState = nil;
|
||||
view.asyncDelegate = pendingState.delegate;
|
||||
view.asyncDataSource = pendingState.dataSource;
|
||||
view.allowsSelection = pendingState.allowsSelection;
|
||||
view.allowsSelectionDuringEditing = pendingState.allowsSelectionDuringEditing;
|
||||
view.allowsMultipleSelection = pendingState.allowsMultipleSelection;
|
||||
view.allowsMultipleSelectionDuringEditing = pendingState.allowsMultipleSelectionDuringEditing;
|
||||
if (pendingState.rangeMode != ASLayoutRangeModeCount) {
|
||||
[view.rangeController updateCurrentRangeWithMode:pendingState.rangeMode];
|
||||
}
|
||||
@@ -215,6 +227,82 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setAllowsSelection:(BOOL)allowsSelection
|
||||
{
|
||||
if ([self pendingState]) {
|
||||
_pendingState.allowsSelection = allowsSelection;
|
||||
} else {
|
||||
ASDisplayNodeAssert([self isNodeLoaded], @"ASTableNode should be loaded if pendingState doesn't exist");
|
||||
self.view.allowsSelection = allowsSelection;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)allowsSelection
|
||||
{
|
||||
if ([self pendingState]) {
|
||||
return _pendingState.allowsSelection;
|
||||
} else {
|
||||
return self.view.allowsSelection;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setAllowsSelectionDuringEditing:(BOOL)allowsSelectionDuringEditing
|
||||
{
|
||||
if ([self pendingState]) {
|
||||
_pendingState.allowsSelectionDuringEditing = allowsSelectionDuringEditing;
|
||||
} else {
|
||||
ASDisplayNodeAssert([self isNodeLoaded], @"ASTableNode should be loaded if pendingState doesn't exist");
|
||||
self.view.allowsSelectionDuringEditing = allowsSelectionDuringEditing;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)allowsSelectionDuringEditing
|
||||
{
|
||||
if ([self pendingState]) {
|
||||
return _pendingState.allowsSelectionDuringEditing;
|
||||
} else {
|
||||
return self.view.allowsSelectionDuringEditing;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setAllowsMultipleSelection:(BOOL)allowsMultipleSelection
|
||||
{
|
||||
if ([self pendingState]) {
|
||||
_pendingState.allowsMultipleSelection = allowsMultipleSelection;
|
||||
} else {
|
||||
ASDisplayNodeAssert([self isNodeLoaded], @"ASTableNode should be loaded if pendingState doesn't exist");
|
||||
self.view.allowsMultipleSelection = allowsMultipleSelection;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)allowsMultipleSelection
|
||||
{
|
||||
if ([self pendingState]) {
|
||||
return _pendingState.allowsMultipleSelection;
|
||||
} else {
|
||||
return self.view.allowsMultipleSelection;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setAllowsMultipleSelectionDuringEditing:(BOOL)allowsMultipleSelectionDuringEditing
|
||||
{
|
||||
if ([self pendingState]) {
|
||||
_pendingState.allowsMultipleSelectionDuringEditing = allowsMultipleSelectionDuringEditing;
|
||||
} else {
|
||||
ASDisplayNodeAssert([self isNodeLoaded], @"ASTableNode should be loaded if pendingState doesn't exist");
|
||||
self.view.allowsMultipleSelectionDuringEditing = allowsMultipleSelectionDuringEditing;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)allowsMultipleSelectionDuringEditing
|
||||
{
|
||||
if ([self pendingState]) {
|
||||
return _pendingState.allowsMultipleSelectionDuringEditing;
|
||||
} else {
|
||||
return self.view.allowsMultipleSelectionDuringEditing;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark ASRangeControllerUpdateRangeProtocol
|
||||
|
||||
- (void)updateCurrentRangeWithMode:(ASLayoutRangeMode)rangeMode
|
||||
@@ -253,6 +341,24 @@ ASEnvironmentCollectionTableSetEnvironmentState(_environmentStateLock)
|
||||
return [self.rangeController setTuningParameters:tuningParameters forRangeMode:rangeMode rangeType:rangeType];
|
||||
}
|
||||
|
||||
#pragma mark - Selection
|
||||
|
||||
- (void)selectRowAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition
|
||||
{
|
||||
ASDisplayNodeAssertMainThread();
|
||||
// TODO: Solve this in a way to be able to remove this restriction (https://github.com/facebook/AsyncDisplayKit/pull/2453#discussion_r84515457)
|
||||
ASDisplayNodeAssert([self isNodeLoaded], @"ASTableNode should be loaded before calling selectRowAtIndexPath");
|
||||
[self.view selectRowAtIndexPath:indexPath animated:animated scrollPosition:scrollPosition];
|
||||
}
|
||||
|
||||
- (void)deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated
|
||||
{
|
||||
ASDisplayNodeAssertMainThread();
|
||||
// TODO: Solve this in a way to be able to remove this restriction (https://github.com/facebook/AsyncDisplayKit/pull/2453#discussion_r84515457)
|
||||
ASDisplayNodeAssert([self isNodeLoaded], @"ASTableNode should be loaded before calling deselectRowAtIndexPath");
|
||||
[self.view deselectRowAtIndexPath:indexPath animated:animated];
|
||||
}
|
||||
|
||||
#pragma mark - Querying Data
|
||||
|
||||
- (NSInteger)numberOfRowsInSection:(NSInteger)section
|
||||
|
||||
Reference in New Issue
Block a user