Skip to content

Commit

Permalink
Passthrough pagingEnabled for ASCollectionNode / ASTableNode (Texture…
Browse files Browse the repository at this point in the history
…Group#1466)

* Passthrough pagingEnabled for ASCollectionNode and ASTableNode

* Add tvOS handling
  • Loading branch information
maicki authored and hebertialmeida committed May 10, 2019
1 parent 7757a60 commit 6346e49
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
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 __TVOS_PROHIBITED;

/**
* The layout used to organize the node's items.
*
Expand Down
27 changes: 27 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,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) {
Expand Down Expand Up @@ -528,6 +533,28 @@ - (BOOL)showsHorizontalScrollIndicator
}
}

#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]) {
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 __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`.
Expand Down
30 changes: 29 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,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)) {
Expand Down Expand Up @@ -366,6 +370,30 @@ - (BOOL)automaticallyAdjustsContentOffset
}
}

#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]) {
Expand Down

0 comments on commit 6346e49

Please sign in to comment.