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

Passthrough pagingEnabled for ASCollectionNode / ASTableNode #1466

Merged
merged 2 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions Source/ASCollectionNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic) BOOL showsHorizontalScrollIndicator;

/**
* A Boolean value that determines whether paging is enabled for the scroll view.
* The default value of this property is NO.
*/
@property (nonatomic, getter=isPagingEnabled) BOOL pagingEnabled;

/**
* The layout used to organize the node's items.
*
Expand Down
23 changes: 23 additions & 0 deletions Source/ASCollectionNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ @interface _ASCollectionPendingState : NSObject {
@property (nonatomic) BOOL animatesContentOffset;
@property (nonatomic) BOOL showsVerticalScrollIndicator;
@property (nonatomic) BOOL showsHorizontalScrollIndicator;
@property (nonatomic) BOOL pagingEnabled;
@end

@implementation _ASCollectionPendingState
Expand All @@ -72,6 +73,7 @@ - (instancetype)init
_animatesContentOffset = NO;
_showsVerticalScrollIndicator = YES;
_showsHorizontalScrollIndicator = YES;
_pagingEnabled = NO;
}
return self;
}
Expand Down Expand Up @@ -197,6 +199,7 @@ - (void)didLoad
view.layoutInspector = pendingState.layoutInspector;
view.showsVerticalScrollIndicator = pendingState.showsVerticalScrollIndicator;
view.showsHorizontalScrollIndicator = pendingState.showsHorizontalScrollIndicator;
view.pagingEnabled = pendingState.pagingEnabled;

// Only apply these flags if they're enabled; the view might come with them turned on.
if (pendingState.alwaysBounceVertical) {
Expand Down Expand Up @@ -528,6 +531,26 @@ - (BOOL)showsHorizontalScrollIndicator
}
}

- (void)setPagingEnabled:(BOOL)pagingEnabled
{
if ([self pendingState]) {
_pendingState.pagingEnabled = pagingEnabled;
} else {
ASDisplayNodeAssert([self isNodeLoaded],
@"ASCollectionNode should be loaded if pendingState doesn't exist");
self.view.pagingEnabled = pagingEnabled;
}
}

- (BOOL)isPagingEnabled
{
if ([self pendingState]) {
return _pendingState.pagingEnabled;
} else {
return self.view.isPagingEnabled;
}
}

- (void)setCollectionViewLayout:(UICollectionViewLayout *)layout
{
if ([self pendingState]) {
Expand Down
6 changes: 6 additions & 0 deletions Source/ASTableNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic) BOOL automaticallyAdjustsContentOffset;

/**
* A Boolean value that determines whether paging is enabled for the scroll view.
* The default value of this property is NO.
*/
@property (nonatomic, getter=isPagingEnabled) BOOL pagingEnabled;

/*
* A Boolean value that determines whether users can select a row.
* If the value of this property is YES (the default), users can select rows. If you set it to NO, they cannot select rows. Setting this property affects cell selection only when the table view is not in editing mode. If you want to restrict selection of cells in editing mode, use `allowsSelectionDuringEditing`.
Expand Down
26 changes: 25 additions & 1 deletion Source/ASTableNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ @interface _ASTablePendingState : NSObject {
@property (nonatomic) CGPoint contentOffset;
@property (nonatomic) BOOL animatesContentOffset;
@property (nonatomic) BOOL automaticallyAdjustsContentOffset;

@property (nonatomic) BOOL pagingEnabled;
@end

@implementation _ASTablePendingState
Expand All @@ -66,6 +66,7 @@ - (instancetype)init
_contentOffset = CGPointZero;
_animatesContentOffset = NO;
_automaticallyAdjustsContentOffset = NO;
_pagingEnabled = NO;
}
return self;
}
Expand Down Expand Up @@ -164,6 +165,7 @@ - (void)didLoad
view.allowsMultipleSelection = pendingState.allowsMultipleSelection;
view.allowsMultipleSelectionDuringEditing = pendingState.allowsMultipleSelectionDuringEditing;
view.automaticallyAdjustsContentOffset = pendingState.automaticallyAdjustsContentOffset;
view.pagingEnabled = pendingState.pagingEnabled;

UIEdgeInsets contentInset = pendingState.contentInset;
if (!UIEdgeInsetsEqualToEdgeInsets(contentInset, UIEdgeInsetsZero)) {
Expand Down Expand Up @@ -366,6 +368,28 @@ - (BOOL)automaticallyAdjustsContentOffset
}
}

- (void)setPagingEnabled:(BOOL)pagingEnabled
{
_ASTablePendingState *pendingState = self.pendingState;
if (pendingState) {
pendingState.pagingEnabled = pagingEnabled;
} else {
ASDisplayNodeAssert([self isNodeLoaded],
@"ASCollectionNode should be loaded if pendingState doesn't exist");
self.view.pagingEnabled = pagingEnabled;
}
}

- (BOOL)isPagingEnabled
{
_ASTablePendingState *pendingState = self.pendingState;
if (pendingState) {
return pendingState.pagingEnabled;
} else {
return self.view.isPagingEnabled;
}
}

- (void)setDelegate:(id <ASTableDelegate>)delegate
{
if ([self pendingState]) {
Expand Down