From 160ac9c7a0e71c1890b7cbbe152b0f24e7611a1f Mon Sep 17 00:00:00 2001 From: Michael Schneider Date: Wed, 24 Apr 2019 09:15:01 -0700 Subject: [PATCH 1/2] Passthrough pagingEnabled for ASCollectionNode and ASTableNode --- Source/ASCollectionNode.h | 6 ++++++ Source/ASCollectionNode.mm | 23 +++++++++++++++++++++++ Source/ASTableNode.h | 6 ++++++ Source/ASTableNode.mm | 26 +++++++++++++++++++++++++- 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/Source/ASCollectionNode.h b/Source/ASCollectionNode.h index fcce974b9..4a9b8167d 100644 --- a/Source/ASCollectionNode.h +++ b/Source/ASCollectionNode.h @@ -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. * diff --git a/Source/ASCollectionNode.mm b/Source/ASCollectionNode.mm index e894f8b5d..0df47e09b 100644 --- a/Source/ASCollectionNode.mm +++ b/Source/ASCollectionNode.mm @@ -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 @@ -72,6 +73,7 @@ - (instancetype)init _animatesContentOffset = NO; _showsVerticalScrollIndicator = YES; _showsHorizontalScrollIndicator = YES; + _pagingEnabled = NO; } return self; } @@ -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) { @@ -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]) { diff --git a/Source/ASTableNode.h b/Source/ASTableNode.h index 9ab7c35b7..d73c23ca0 100644 --- a/Source/ASTableNode.h +++ b/Source/ASTableNode.h @@ -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`. diff --git a/Source/ASTableNode.mm b/Source/ASTableNode.mm index 496942017..1f2ba70f9 100644 --- a/Source/ASTableNode.mm +++ b/Source/ASTableNode.mm @@ -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 @@ -66,6 +66,7 @@ - (instancetype)init _contentOffset = CGPointZero; _animatesContentOffset = NO; _automaticallyAdjustsContentOffset = NO; + _pagingEnabled = NO; } return self; } @@ -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)) { @@ -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 )delegate { if ([self pendingState]) { From 8ddc92892cff47212a61587f001657747966673a Mon Sep 17 00:00:00 2001 From: Michael Schneider Date: Thu, 25 Apr 2019 11:36:56 -0700 Subject: [PATCH 2/2] Add tvOS handling --- Source/ASCollectionNode.h | 2 +- Source/ASCollectionNode.mm | 4 ++++ Source/ASTableNode.h | 2 +- Source/ASTableNode.mm | 4 ++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Source/ASCollectionNode.h b/Source/ASCollectionNode.h index 4a9b8167d..521922a51 100644 --- a/Source/ASCollectionNode.h +++ b/Source/ASCollectionNode.h @@ -129,7 +129,7 @@ NS_ASSUME_NONNULL_BEGIN * 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; +@property (nonatomic, getter=isPagingEnabled) BOOL pagingEnabled __TVOS_PROHIBITED; /** * The layout used to organize the node's items. diff --git a/Source/ASCollectionNode.mm b/Source/ASCollectionNode.mm index 0df47e09b..6243da6b4 100644 --- a/Source/ASCollectionNode.mm +++ b/Source/ASCollectionNode.mm @@ -199,7 +199,9 @@ - (void)didLoad 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) { @@ -531,6 +533,7 @@ - (BOOL)showsHorizontalScrollIndicator } } +#if !TARGET_OS_TV - (void)setPagingEnabled:(BOOL)pagingEnabled { if ([self pendingState]) { @@ -550,6 +553,7 @@ - (BOOL)isPagingEnabled return self.view.isPagingEnabled; } } +#endif - (void)setCollectionViewLayout:(UICollectionViewLayout *)layout { diff --git a/Source/ASTableNode.h b/Source/ASTableNode.h index d73c23ca0..772f3a7ec 100644 --- a/Source/ASTableNode.h +++ b/Source/ASTableNode.h @@ -81,7 +81,7 @@ NS_ASSUME_NONNULL_BEGIN * 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; +@property (nonatomic, getter=isPagingEnabled) BOOL pagingEnabled __TVOS_PROHIBITED; /* * A Boolean value that determines whether users can select a row. diff --git a/Source/ASTableNode.mm b/Source/ASTableNode.mm index 1f2ba70f9..8af189a5d 100644 --- a/Source/ASTableNode.mm +++ b/Source/ASTableNode.mm @@ -165,7 +165,9 @@ - (void)didLoad 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)) { @@ -368,6 +370,7 @@ - (BOOL)automaticallyAdjustsContentOffset } } +#if !TARGET_OS_TV - (void)setPagingEnabled:(BOOL)pagingEnabled { _ASTablePendingState *pendingState = self.pendingState; @@ -389,6 +392,7 @@ - (BOOL)isPagingEnabled return self.view.isPagingEnabled; } } +#endif - (void)setDelegate:(id )delegate {