mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
[ASCellNode] Fix selection / highlight implementation
This commit is contained in:
@@ -42,20 +42,39 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
||||
- (void)setNode:(ASCellNode *)node
|
||||
{
|
||||
_node = node;
|
||||
node.selected = self.selected;
|
||||
node.highlighted = self.highlighted;
|
||||
if (node.selected != self.selected) {
|
||||
node.selected = self.selected;
|
||||
}
|
||||
if (node.highlighted != self.highlighted) {
|
||||
node.highlighted = self.highlighted;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setSelected:(BOOL)selected
|
||||
{
|
||||
[super setSelected:selected];
|
||||
_node.selected = selected;
|
||||
if (selected != self.selected) {
|
||||
[super setSelected:selected];
|
||||
}
|
||||
if (selected != _node.selected) {
|
||||
_node.selected = selected;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setHighlighted:(BOOL)highlighted
|
||||
{
|
||||
[super setHighlighted:highlighted];
|
||||
_node.highlighted = highlighted;
|
||||
if (highlighted != self.highlighted) {
|
||||
[super setHighlighted:highlighted];
|
||||
}
|
||||
if (highlighted != _node.highlighted) {
|
||||
_node.highlighted = highlighted;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)prepareForReuse
|
||||
{
|
||||
// Need to clear node pointer before UIKit calls setSelected:NO / setHighlighted:NO on its cells
|
||||
self.node = nil;
|
||||
[super prepareForReuse];
|
||||
}
|
||||
|
||||
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
|
||||
@@ -98,7 +117,7 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
||||
#pragma mark -
|
||||
#pragma mark ASCollectionView.
|
||||
|
||||
@interface ASCollectionView () <ASRangeControllerDataSource, ASRangeControllerDelegate, ASDataControllerSource, ASCellNodeLayoutDelegate, ASDelegateProxyInterceptor, ASBatchFetchingScrollView, ASDataControllerEnvironmentDelegate> {
|
||||
@interface ASCollectionView () <ASRangeControllerDataSource, ASRangeControllerDelegate, ASDataControllerSource, ASCellNodeInteractionDelegate, ASDelegateProxyInterceptor, ASBatchFetchingScrollView, ASDataControllerEnvironmentDelegate> {
|
||||
ASCollectionViewProxy *_proxyDataSource;
|
||||
ASCollectionViewProxy *_proxyDelegate;
|
||||
|
||||
@@ -864,8 +883,8 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
||||
return ^{
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
[node enterHierarchyState:ASHierarchyStateRangeManaged];
|
||||
if (node.layoutDelegate == nil) {
|
||||
node.layoutDelegate = strongSelf;
|
||||
if (node.interactionDelegate == nil) {
|
||||
node.interactionDelegate = strongSelf;
|
||||
}
|
||||
return node;
|
||||
};
|
||||
@@ -879,8 +898,8 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
||||
|
||||
ASCellNode *node = block();
|
||||
[node enterHierarchyState:ASHierarchyStateRangeManaged];
|
||||
if (node.layoutDelegate == nil) {
|
||||
node.layoutDelegate = strongSelf;
|
||||
if (node.interactionDelegate == nil) {
|
||||
node.interactionDelegate = strongSelf;
|
||||
}
|
||||
return node;
|
||||
};
|
||||
@@ -1127,6 +1146,25 @@ static NSString * const kCellReuseIdentifier = @"_ASCollectionViewCell";
|
||||
}
|
||||
|
||||
#pragma mark - ASCellNodeDelegate
|
||||
- (void)nodeSelectedStateDidChange:(ASCellNode *)node
|
||||
{
|
||||
NSIndexPath *indexPath = [self indexPathForNode:node];
|
||||
if (indexPath) {
|
||||
if (node.isSelected) {
|
||||
[self selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
|
||||
} else {
|
||||
[self deselectItemAtIndexPath:indexPath animated:NO];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)nodeHighlightedStateDidChange:(ASCellNode *)node
|
||||
{
|
||||
NSIndexPath *indexPath = [self indexPathForNode:node];
|
||||
if (indexPath) {
|
||||
[self cellForItemAtIndexPath:indexPath].highlighted = node.isHighlighted;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)nodeDidRelayout:(ASCellNode *)node sizeChanged:(BOOL)sizeChanged
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user