This repository has been archived by the owner on Feb 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Added selection API to ASTableNode and ASCollectionNode #2453
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c24c633
Added selection API to ASTableNode and ASCollectionNode (#2450)
george-gw e544d23
Updated test case to use collectionNode instead of collectionView for…
george-gw 9ad983d
Fixed typos.
george-gw 0fcda95
Added assigns to the different properties.
george-gw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,11 @@ | |
@interface _ASTablePendingState : NSObject | ||
@property (weak, nonatomic) id <ASTableDelegate> delegate; | ||
@property (weak, nonatomic) id <ASTableDataSource> dataSource; | ||
@property (assign, nonatomic) ASLayoutRangeMode rangeMode; | ||
@property (nonatomic, assign) ASLayoutRangeMode rangeMode; | ||
@property (nonatomic, assign) BOOL allowsSelection; | ||
@property (nonatomic, assign) BOOL allowsSelectionDuringEditing; | ||
@property (nonatomic, assign) BOOL allowsMultipleSelection; | ||
@property (nonatomic, assign) BOOL allowsMultipleSelectionDuringEditing; | ||
@end | ||
|
||
@implementation _ASTablePendingState | ||
|
@@ -33,6 +37,10 @@ - (instancetype)init | |
self = [super init]; | ||
if (self) { | ||
_rangeMode = ASLayoutRangeModeCount; | ||
_allowsSelection = YES; | ||
_allowsSelectionDuringEditing = NO; | ||
_allowsMultipleSelection = NO; | ||
_allowsMultipleSelectionDuringEditing = NO; | ||
} | ||
return self; | ||
} | ||
|
@@ -104,6 +112,10 @@ - (void)didLoad | |
self.pendingState = nil; | ||
view.asyncDelegate = pendingState.delegate; | ||
view.asyncDataSource = pendingState.dataSource; | ||
view.allowsSelection = pendingState.allowsSelection; | ||
view.allowsSelectionDuringEditing = pendingState.allowsSelectionDuringEditing; | ||
view.allowsMultipleSelection = pendingState.allowsMultipleSelection; | ||
view.allowsMultipleSelectionDuringEditing = pendingState.allowsMultipleSelectionDuringEditing; | ||
if (pendingState.rangeMode != ASLayoutRangeModeCount) { | ||
[view.rangeController updateCurrentRangeWithMode:pendingState.rangeMode]; | ||
} | ||
|
@@ -215,6 +227,82 @@ - (void)setDataSource:(id <ASTableDataSource>)dataSource | |
} | ||
} | ||
|
||
- (void)setAllowsSelection:(BOOL)allowsSelection | ||
{ | ||
if ([self pendingState]) { | ||
_pendingState.allowsSelection = allowsSelection; | ||
} else { | ||
ASDisplayNodeAssert([self isNodeLoaded], @"ASTableNode should be loaded if pendingState doesn't exist"); | ||
self.view.allowsSelection = allowsSelection; | ||
} | ||
} | ||
|
||
- (BOOL)allowsSelection | ||
{ | ||
if ([self pendingState]) { | ||
return _pendingState.allowsSelection; | ||
} else { | ||
return self.view.allowsSelection; | ||
} | ||
} | ||
|
||
- (void)setAllowsSelectionDuringEditing:(BOOL)allowsSelectionDuringEditing | ||
{ | ||
if ([self pendingState]) { | ||
_pendingState.allowsSelectionDuringEditing = allowsSelectionDuringEditing; | ||
} else { | ||
ASDisplayNodeAssert([self isNodeLoaded], @"ASTableNode should be loaded if pendingState doesn't exist"); | ||
self.view.allowsSelectionDuringEditing = allowsSelectionDuringEditing; | ||
} | ||
} | ||
|
||
- (BOOL)allowsSelectionDuringEditing | ||
{ | ||
if ([self pendingState]) { | ||
return _pendingState.allowsSelectionDuringEditing; | ||
} else { | ||
return self.view.allowsSelectionDuringEditing; | ||
} | ||
} | ||
|
||
- (void)setAllowsMultipleSelection:(BOOL)allowsMultipleSelection | ||
{ | ||
if ([self pendingState]) { | ||
_pendingState.allowsMultipleSelection = allowsMultipleSelection; | ||
} else { | ||
ASDisplayNodeAssert([self isNodeLoaded], @"ASTableNode should be loaded if pendingState doesn't exist"); | ||
self.view.allowsMultipleSelection = allowsMultipleSelection; | ||
} | ||
} | ||
|
||
- (BOOL)allowsMultipleSelection | ||
{ | ||
if ([self pendingState]) { | ||
return _pendingState.allowsMultipleSelection; | ||
} else { | ||
return self.view.allowsMultipleSelection; | ||
} | ||
} | ||
|
||
- (void)setAllowsMultipleSelectionDuringEditing:(BOOL)allowsMultipleSelectionDuringEditing | ||
{ | ||
if ([self pendingState]) { | ||
_pendingState.allowsMultipleSelectionDuringEditing = allowsMultipleSelectionDuringEditing; | ||
} else { | ||
ASDisplayNodeAssert([self isNodeLoaded], @"ASTableNode should be loaded if pendingState doesn't exist"); | ||
self.view.allowsMultipleSelectionDuringEditing = allowsMultipleSelectionDuringEditing; | ||
} | ||
} | ||
|
||
- (BOOL)allowsMultipleSelectionDuringEditing | ||
{ | ||
if ([self pendingState]) { | ||
return _pendingState.allowsMultipleSelectionDuringEditing; | ||
} else { | ||
return self.view.allowsMultipleSelectionDuringEditing; | ||
} | ||
} | ||
|
||
#pragma mark ASRangeControllerUpdateRangeProtocol | ||
|
||
- (void)updateCurrentRangeWithMode:(ASLayoutRangeMode)rangeMode | ||
|
@@ -253,6 +341,24 @@ - (void)setTuningParameters:(ASRangeTuningParameters)tuningParameters forRangeMo | |
return [self.rangeController setTuningParameters:tuningParameters forRangeMode:rangeMode rangeType:rangeType]; | ||
} | ||
|
||
#pragma mark - Selection | ||
|
||
- (void)selectRowAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UITableViewScrollPosition)scrollPosition | ||
{ | ||
ASDisplayNodeAssertMainThread(); | ||
// TODO: Solve this in a way to be able to remove this restriction (https://github.com/facebook/AsyncDisplayKit/pull/2453#discussion_r84515457) | ||
ASDisplayNodeAssert([self isNodeLoaded], @"ASTableNode should be loaded before calling selectRowAtIndexPath"); | ||
[self.view selectRowAtIndexPath:indexPath animated:animated scrollPosition:scrollPosition]; | ||
} | ||
|
||
- (void)deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated | ||
{ | ||
ASDisplayNodeAssertMainThread(); | ||
// TODO: Solve this in a way to be able to remove this restriction (https://github.com/facebook/AsyncDisplayKit/pull/2453#discussion_r84515457) | ||
ASDisplayNodeAssert([self isNodeLoaded], @"ASTableNode should be loaded before calling deselectRowAtIndexPath"); | ||
[self.view deselectRowAtIndexPath:indexPath animated:animated]; | ||
} | ||
|
||
#pragma mark - Querying Data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add white space below |
||
|
||
- (NSInteger)numberOfRowsInSection:(NSInteger)section | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future it will be nice to remove this restriction. It would require that we have a clean method for ensuring that the view is loaded, that the initial reload has been called, and that all updates are committed. Today we could cobble together all that into a method but it would be ugly and there are other potential hazards (what if we're inside
willDisplayCell:forItemAtIndexPath:
and waiting is unsafe, what if we're zero-size, etc.) That will come later and I think that this is plenty for the medium-term.Also, would you be willing to add
ASDisplayNodeAssertMainThread()
in these methods?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I added a todo referring to your discussion post.
I added the
ASDisplayNodeAssertMainThread()
, I didn't add it before because the code that this method calls checks for that assertion. But I suppose it's better to have it in case the implementation changes later on.