Skip to content

Commit

Permalink
Added moveToBeginningOfDocument / moveToEndOfDocument support
Browse files Browse the repository at this point in the history
  • Loading branch information
kettch committed Jun 1, 2016
1 parent 916315b commit ce2d3c6
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion JNWCollectionView/JNWCollectionViewFramework.m
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,30 @@ - (NSArray *)allIndexPaths {
return indexPaths.copy;
}

- (NSIndexPath *)firstIndexPath {
NSIndexPath *indexPath = nil;
if (self.data.numberOfSections > 0) {
JNWCollectionViewSection section = self.data.sections[0];
if (section.numberOfItems > 0) {
indexPath = [NSIndexPath jnw_indexPathForItem:0 inSection:0];
}
}
return indexPath;
}

- (NSIndexPath *)lastIndexPath {
NSIndexPath *indexPath = nil;
NSInteger numberOfSections = self.data.numberOfSections;
if (numberOfSections > 0) {
JNWCollectionViewSection section = self.data.sections[numberOfSections - 1];
NSInteger numberOfItems = section.numberOfItems;
if (numberOfItems > 0) {
indexPath = [NSIndexPath jnw_indexPathForItem:numberOfItems - 1 inSection:numberOfSections - 1];
}
}
return indexPath;
}

- (NSArray *)indexPathsForItemsInRect:(CGRect)rect {
if (CGRectEqualToRect(rect, CGRectZero))
return [NSArray array];
Expand Down Expand Up @@ -1056,7 +1080,8 @@ - (void)rightClickInCollectionViewCell:(JNWCollectionViewCell *)cell withEvent:(

- (void)moveUp:(id)sender {
NSIndexPath *toSelect = [self.collectionViewLayout indexPathForNextItemInDirection:JNWCollectionViewDirectionUp currentIndexPath:[self indexPathForSelectedItem]];
[self selectItemAtIndexPath:toSelect atScrollPosition:JNWCollectionViewScrollPositionNearest animated:YES];}
[self selectItemAtIndexPath:toSelect atScrollPosition:JNWCollectionViewScrollPositionNearest animated:YES];
}

- (void)moveUpAndModifySelection:(id)sender {
NSIndexPath *toSelect = [self.collectionViewLayout indexPathForNextItemInDirection:JNWCollectionViewDirectionUp currentIndexPath:[self indexPathForSelectedItem]];
Expand Down Expand Up @@ -1093,6 +1118,20 @@ - (void)moveLeftAndModifySelection:(id)sender {
[self selectItemAtIndexPath:toSelect atScrollPosition:JNWCollectionViewScrollPositionNearest animated:YES selectionType:JNWCollectionViewSelectionTypeExtending];
}

- (void)moveToBeginningOfDocument:(id)sender {
NSIndexPath *toSelect = [self firstIndexPath];
if (toSelect) {
[self selectItemAtIndexPath:toSelect atScrollPosition:JNWCollectionViewScrollPositionNearest animated:YES];
}
}

- (void)moveToEndOfDocument:(id)sender {
NSIndexPath *toSelect = [self lastIndexPath];
if (toSelect) {
[self selectItemAtIndexPath:toSelect atScrollPosition:JNWCollectionViewScrollPositionNearest animated:YES];
}
}

- (void)selectAll:(id)sender {
[self selectItemsAtIndexPaths:[self allIndexPaths] animated:YES];
}
Expand Down

0 comments on commit ce2d3c6

Please sign in to comment.