Passthrough pagingEnabled for ASCollectionNode / ASTableNode (#1466)

* Passthrough pagingEnabled for ASCollectionNode and ASTableNode

* Add tvOS handling
This commit is contained in:
Michael Schneider
2019-04-25 14:02:10 -07:00
committed by GitHub
parent bb6c89e3ba
commit 0cfafca9f6
4 changed files with 68 additions and 1 deletions
+6
View File
@@ -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 __TVOS_PROHIBITED;
/**
* The layout used to organize the node's items.
*
+27
View File
@@ -52,6 +52,7 @@
@property (nonatomic) BOOL animatesContentOffset;
@property (nonatomic) BOOL showsVerticalScrollIndicator;
@property (nonatomic) BOOL showsHorizontalScrollIndicator;
@property (nonatomic) BOOL pagingEnabled;
@end
@implementation _ASCollectionPendingState
@@ -72,6 +73,7 @@
_animatesContentOffset = NO;
_showsVerticalScrollIndicator = YES;
_showsHorizontalScrollIndicator = YES;
_pagingEnabled = NO;
}
return self;
}
@@ -197,6 +199,9 @@
view.layoutInspector = pendingState.layoutInspector;
view.showsVerticalScrollIndicator = pendingState.showsVerticalScrollIndicator;
view.showsHorizontalScrollIndicator = pendingState.showsHorizontalScrollIndicator;
#if !TARGET_OS_TV
view.pagingEnabled = pendingState.pagingEnabled;
#endif
// Only apply these flags if they're enabled; the view might come with them turned on.
if (pendingState.alwaysBounceVertical) {
@@ -528,6 +533,28 @@
}
}
#if !TARGET_OS_TV
- (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;
}
}
#endif
- (void)setCollectionViewLayout:(UICollectionViewLayout *)layout
{
if ([self pendingState]) {
+6
View File
@@ -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 __TVOS_PROHIBITED;
/*
* 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`.
+29 -1
View File
@@ -43,7 +43,7 @@
@property (nonatomic) CGPoint contentOffset;
@property (nonatomic) BOOL animatesContentOffset;
@property (nonatomic) BOOL automaticallyAdjustsContentOffset;
@property (nonatomic) BOOL pagingEnabled;
@end
@implementation _ASTablePendingState
@@ -66,6 +66,7 @@
_contentOffset = CGPointZero;
_animatesContentOffset = NO;
_automaticallyAdjustsContentOffset = NO;
_pagingEnabled = NO;
}
return self;
}
@@ -164,6 +165,9 @@
view.allowsMultipleSelection = pendingState.allowsMultipleSelection;
view.allowsMultipleSelectionDuringEditing = pendingState.allowsMultipleSelectionDuringEditing;
view.automaticallyAdjustsContentOffset = pendingState.automaticallyAdjustsContentOffset;
#if !TARGET_OS_TV
view.pagingEnabled = pendingState.pagingEnabled;
#endif
UIEdgeInsets contentInset = pendingState.contentInset;
if (!UIEdgeInsetsEqualToEdgeInsets(contentInset, UIEdgeInsetsZero)) {
@@ -366,6 +370,30 @@
}
}
#if !TARGET_OS_TV
- (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;
}
}
#endif
- (void)setDelegate:(id <ASTableDelegate>)delegate
{
if ([self pendingState]) {