Skip to content

Commit

Permalink
Merge pull request #101 from jwilling/scroll-direction
Browse files Browse the repository at this point in the history
Add preliminary scroll direction support
  • Loading branch information
jwilling committed Jan 31, 2014
2 parents ff014de + c1ca228 commit 03694b4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
23 changes: 20 additions & 3 deletions JNWCollectionView/JNWCollectionViewFramework.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ static void JNWCollectionViewCommonInit(JNWCollectionView *collectionView) {

// Set the document view to a custom class that returns YES to -isFlipped.
collectionView.documentView = [[JNWCollectionViewDocumentView alloc] initWithFrame:CGRectZero];

collectionView.hasHorizontalScroller = NO;
collectionView.hasVerticalScroller = YES;

// We don't want to perform an initial layout pass until the user has called -reloadData.
collectionView->_collectionViewFlags.wantsLayout = NO;
Expand Down Expand Up @@ -591,11 +588,31 @@ - (void)performFullRelayoutForcingSubviewsReset:(BOOL)forceReset {
- (void)layoutDocumentView {
if (!_collectionViewFlags.wantsLayout)
return;

[self updateScrollDirection];

NSView *documentView = self.documentView;
documentView.frameSize = self.data.encompassingSize;
}

- (void)updateScrollDirection {
switch (self.collectionViewLayout.scrollDirection) {
case JNWCollectionViewScrollDirectionVertical:
self.hasVerticalScroller = YES;
self.hasHorizontalScroller = NO;
break;
case JNWCollectionViewScrollDirectionHorizontal:
self.hasVerticalScroller = NO;
self.hasHorizontalScroller = YES;
break;
case JNWCollectionViewScrollDirectionBoth:
default:
self.hasVerticalScroller = YES;
self.hasHorizontalScroller = YES;
break;
}
}

- (CGSize)visibleSize {
return self.documentVisibleRect.size;
}
Expand Down
18 changes: 18 additions & 0 deletions JNWCollectionView/JNWCollectionViewLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ typedef NS_ENUM(NSInteger, JNWCollectionViewDirection) {
JNWCollectionViewDirectionDown
};

typedef NS_ENUM(NSInteger, JNWCollectionViewScrollDirection) {
JNWCollectionViewScrollDirectionVertical,
JNWCollectionViewScrollDirectionHorizontal,
JNWCollectionViewScrollDirectionBoth
};

@interface JNWCollectionViewLayoutAttributes : NSObject
@property (nonatomic, assign) CGRect frame;
@property (nonatomic, assign) CGFloat alpha;
Expand Down Expand Up @@ -104,6 +110,18 @@ typedef NS_ENUM(NSInteger, JNWCollectionViewDirection) {
/// Defaults to CGSizeZero, which means it will fit the collection view's frame.
- (CGSize)contentSize;

/// The scroll direction determines which way the collection view will show scroll indicators.
///
/// Subclasses should override this method to change the scroll direction.
///
/// Note that if the content view is larger than the bounds of the collection view, the content will
/// still be scrollable, even if the scroll indicators do not show up. To prevent this, do not make
/// the content view larger than the collection view itself in the direction in which you do not want
/// scrolling.
///
/// Defaults to JNWCollectionViewScrollDirectionVertical.
- (JNWCollectionViewScrollDirection)scrollDirection;

/// Subclasses must implement this method for arrowed selection to work.
- (NSIndexPath *)indexPathForNextItemInDirection:(JNWCollectionViewDirection)direction currentIndexPath:(NSIndexPath *)currentIndexPath;

Expand Down
4 changes: 4 additions & 0 deletions JNWCollectionView/JNWCollectionViewLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ - (CGSize)contentSize {
return CGSizeZero;
}

- (JNWCollectionViewScrollDirection)scrollDirection {
return JNWCollectionViewScrollDirectionVertical;
}

- (NSIndexPath *)indexPathForNextItemInDirection:(JNWCollectionViewDirection)direction currentIndexPath:(NSIndexPath *)currentIndexPath {
return currentIndexPath;
}
Expand Down

0 comments on commit 03694b4

Please sign in to comment.