Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preliminary scroll direction support #101

Merged
merged 1 commit into from
Jan 31, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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