mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Clean up and test registration of internal supplementary node kinds
This commit is contained in:
@@ -33,8 +33,7 @@
|
|||||||
_pendingNodes = [NSMutableDictionary dictionary];
|
_pendingNodes = [NSMutableDictionary dictionary];
|
||||||
_pendingIndexPaths = [NSMutableDictionary dictionary];
|
_pendingIndexPaths = [NSMutableDictionary dictionary];
|
||||||
|
|
||||||
NSArray *elementKinds = [self.collectionDataSource supplementaryNodeKindsInDataController:self];
|
[[self supplementaryKinds] enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
|
||||||
[elementKinds enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
|
|
||||||
LOG(@"Populating elements of kind: %@", kind);
|
LOG(@"Populating elements of kind: %@", kind);
|
||||||
NSMutableArray *indexPaths = [NSMutableArray array];
|
NSMutableArray *indexPaths = [NSMutableArray array];
|
||||||
NSMutableArray *nodes = [NSMutableArray array];
|
NSMutableArray *nodes = [NSMutableArray array];
|
||||||
@@ -76,8 +75,7 @@
|
|||||||
|
|
||||||
- (void)prepareForInsertSections:(NSIndexSet *)sections
|
- (void)prepareForInsertSections:(NSIndexSet *)sections
|
||||||
{
|
{
|
||||||
NSArray *elementKinds = [self.collectionDataSource supplementaryNodeKindsInDataController:self];
|
[[self supplementaryKinds] enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
|
||||||
[elementKinds enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
|
|
||||||
LOG(@"Populating elements of kind: %@, for sections: %@", kind, sections);
|
LOG(@"Populating elements of kind: %@, for sections: %@", kind, sections);
|
||||||
NSMutableArray *nodes = [NSMutableArray array];
|
NSMutableArray *nodes = [NSMutableArray array];
|
||||||
NSMutableArray *indexPaths = [NSMutableArray array];
|
NSMutableArray *indexPaths = [NSMutableArray array];
|
||||||
@@ -107,8 +105,7 @@
|
|||||||
|
|
||||||
- (void)willDeleteSections:(NSIndexSet *)sections
|
- (void)willDeleteSections:(NSIndexSet *)sections
|
||||||
{
|
{
|
||||||
NSArray *elementKinds = [self.collectionDataSource supplementaryNodeKindsInDataController:self];
|
[[self supplementaryKinds] enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
|
||||||
[elementKinds enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
|
|
||||||
NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet([self editingNodesOfKind:kind], sections);
|
NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet([self editingNodesOfKind:kind], sections);
|
||||||
|
|
||||||
[self deleteNodesOfKind:kind atIndexPaths:indexPaths completion:nil];
|
[self deleteNodesOfKind:kind atIndexPaths:indexPaths completion:nil];
|
||||||
@@ -118,8 +115,7 @@
|
|||||||
|
|
||||||
- (void)prepareForReloadSections:(NSIndexSet *)sections
|
- (void)prepareForReloadSections:(NSIndexSet *)sections
|
||||||
{
|
{
|
||||||
NSArray *elementKinds = [self.collectionDataSource supplementaryNodeKindsInDataController:self];
|
[[self supplementaryKinds] enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
|
||||||
[elementKinds enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
|
|
||||||
NSMutableArray *nodes = [NSMutableArray array];
|
NSMutableArray *nodes = [NSMutableArray array];
|
||||||
NSMutableArray *indexPaths = [NSMutableArray array];
|
NSMutableArray *indexPaths = [NSMutableArray array];
|
||||||
[self _populateSupplementaryNodesOfKind:kind withSections:sections mutableNodes:nodes mutableIndexPaths:indexPaths];
|
[self _populateSupplementaryNodesOfKind:kind withSections:sections mutableNodes:nodes mutableIndexPaths:indexPaths];
|
||||||
@@ -145,8 +141,7 @@
|
|||||||
|
|
||||||
- (void)willMoveSection:(NSInteger)section toSection:(NSInteger)newSection
|
- (void)willMoveSection:(NSInteger)section toSection:(NSInteger)newSection
|
||||||
{
|
{
|
||||||
NSArray *elementKinds = [self.collectionDataSource supplementaryNodeKindsInDataController:self];
|
[[self supplementaryKinds] enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
|
||||||
[elementKinds enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger idx, BOOL *stop) {
|
|
||||||
NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet([self editingNodesOfKind:kind], [NSIndexSet indexSetWithIndex:section]);
|
NSArray *indexPaths = ASIndexPathsForMultidimensionalArrayAtIndexSet([self editingNodesOfKind:kind], [NSIndexSet indexSetWithIndex:section]);
|
||||||
NSArray *nodes = ASFindElementsInMultidimensionalArrayAtIndexPaths([self editingNodesOfKind:kind], indexPaths);
|
NSArray *nodes = ASFindElementsInMultidimensionalArrayAtIndexPaths([self editingNodesOfKind:kind], indexPaths);
|
||||||
[self deleteNodesOfKind:kind atIndexPaths:indexPaths completion:nil];
|
[self deleteNodesOfKind:kind atIndexPaths:indexPaths completion:nil];
|
||||||
@@ -209,6 +204,11 @@
|
|||||||
|
|
||||||
#pragma mark - Private Helpers
|
#pragma mark - Private Helpers
|
||||||
|
|
||||||
|
- (NSArray *)supplementaryKinds
|
||||||
|
{
|
||||||
|
return [self.collectionDataSource supplementaryNodeKindsInDataController:self];
|
||||||
|
}
|
||||||
|
|
||||||
- (id<ASCollectionDataControllerSource>)collectionDataSource
|
- (id<ASCollectionDataControllerSource>)collectionDataSource
|
||||||
{
|
{
|
||||||
return (id<ASCollectionDataControllerSource>)self.dataSource;
|
return (id<ASCollectionDataControllerSource>)self.dataSource;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#import <XCTest/XCTest.h>
|
#import <XCTest/XCTest.h>
|
||||||
#import "ASCollectionView.h"
|
#import "ASCollectionView.h"
|
||||||
|
#import "ASCollectionDataController.h"
|
||||||
#import "ASCollectionViewFlowLayoutInspector.h"
|
#import "ASCollectionViewFlowLayoutInspector.h"
|
||||||
|
|
||||||
@interface ASCollectionViewTestDelegate : NSObject <ASCollectionViewDataSource, ASCollectionViewDelegate>
|
@interface ASCollectionViewTestDelegate : NSObject <ASCollectionViewDataSource, ASCollectionViewDelegate>
|
||||||
@@ -74,6 +75,12 @@
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@interface ASCollectionView (InternalTesting)
|
||||||
|
|
||||||
|
- (NSArray *)supplementaryNodeKindsInDataController:(ASCollectionDataController *)dataController;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@interface ASCollectionViewTests : XCTestCase
|
@interface ASCollectionViewTests : XCTestCase
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -95,6 +102,14 @@
|
|||||||
XCTAssert(collectionView.layoutDelegate == nil, @"should not set a layout delegate for custom layouts");
|
XCTAssert(collectionView.layoutDelegate == nil, @"should not set a layout delegate for custom layouts");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)testThatRegisteringASupplementaryNodeStoresItForIntrospection
|
||||||
|
{
|
||||||
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
||||||
|
ASCollectionView *collectionView = [[ASCollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
||||||
|
[collectionView registerSupplementaryNodeOfKind:UICollectionElementKindSectionHeader];
|
||||||
|
XCTAssertEqualObjects([collectionView supplementaryNodeKindsInDataController:nil], @[UICollectionElementKindSectionHeader]);
|
||||||
|
}
|
||||||
|
|
||||||
- (void)DISABLED_testCollectionViewController
|
- (void)DISABLED_testCollectionViewController
|
||||||
{
|
{
|
||||||
ASCollectionViewTestController *testController = [[ASCollectionViewTestController alloc] initWithNibName:nil bundle:nil];
|
ASCollectionViewTestController *testController = [[ASCollectionViewTestController alloc] initWithNibName:nil bundle:nil];
|
||||||
|
|||||||
Reference in New Issue
Block a user