-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Added selection API to ASTableNode and ASCollectionNode #2453
Conversation
… the selection tests.
_pendingState.allowsMultipleSelection = allowsMultipleSelection; | ||
} else { | ||
ASDisplayNodeAssert([self isNodeLoaded], @"ASCollectionNode should be loaded if pendingState doesn't exist"); | ||
self.view.allowsSelection = allowsMultipleSelection; |
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.
Typo
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.
Good catch on all 4 of those, fixed!
_pendingState.allowsSelectionDuringEditing = allowsSelectionDuringEditing; | ||
} else { | ||
ASDisplayNodeAssert([self isNodeLoaded], @"ASTableNode should be loaded if pendingState doesn't exist"); | ||
self.view.allowsSelection = allowsSelectionDuringEditing; |
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.
Typo
_pendingState.allowsMultipleSelection = allowsMultipleSelection; | ||
} else { | ||
ASDisplayNodeAssert([self isNodeLoaded], @"ASTableNode should be loaded if pendingState doesn't exist"); | ||
self.view.allowsSelection = allowsMultipleSelection; |
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.
Typo
_pendingState.allowsMultipleSelectionDuringEditing = allowsMultipleSelectionDuringEditing; | ||
} else { | ||
ASDisplayNodeAssert([self isNodeLoaded], @"ASTableNode should be loaded if pendingState doesn't exist"); | ||
self.view.allowsSelection = allowsMultipleSelectionDuringEditing; |
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.
Typo
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.
Hey @george-gw thanks for building this! It's really great to have more hands building out these new features.
|
||
- (void)selectItemAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UICollectionViewScrollPosition)scrollPosition | ||
{ | ||
ASDisplayNodeAssert([self isNodeLoaded], @"ASCollectionNode should be loaded before calling selectItemAtIndexPath"); |
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.
test this please |
Added asserts for main thread. Updated ASCollectionViewTests for multiple selections for nodes.
I had updated the test case that was using collectionView to use collectionNode, I just added some more tests to check if multiple selection works. |
* A Boolean value that indicates whether users can select items in the collection node. | ||
* If the value of this property is YES (the default), users can select items. If you want more fine-grained control over the selection of items, you must provide a delegate object and implement the appropriate methods of the UICollectionNodeDelegate protocol. | ||
*/ | ||
@property (nonatomic) BOOL allowsSelection; |
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.
Add assign
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.
All done, I took the liberty to change the order of (nonatomic and assign) of two other properties to keep the consistency with the rest of the framework.
* This property controls whether multiple items can be selected simultaneously. The default value of this property is NO. | ||
* When the value of this property is YES, tapping a cell adds it to the current selection (assuming the delegate permits the cell to be selected). Tapping the cell again removes it from the selection. | ||
*/ | ||
@property (nonatomic) BOOL allowsMultipleSelection; |
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.
Add assign
@@ -28,6 +28,8 @@ @interface _ASCollectionPendingState : NSObject | |||
@property (weak, nonatomic) id <ASCollectionDelegate> delegate; | |||
@property (weak, nonatomic) id <ASCollectionDataSource> dataSource; | |||
@property (assign, nonatomic) ASLayoutRangeMode rangeMode; | |||
@property (nonatomic) BOOL allowsSelection; // default is YES | |||
@property (nonatomic) BOOL allowsMultipleSelection; // default is NO |
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.
Add assign
on both
* 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`. | ||
*/ | ||
@property (nonatomic) BOOL allowsSelection; |
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.
Add assign
* A Boolean value that determines whether users can select cells while the table view is in editing mode. | ||
* If the value of this property is YES, users can select rows during editing. The default value is NO. If you want to restrict selection of cells regardless of mode, use allowsSelection. | ||
*/ | ||
@property (nonatomic) BOOL allowsSelectionDuringEditing; |
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.
Add assign
* A Boolean value that determines whether users can select more than one row outside of editing mode. | ||
* This property controls whether multiple rows can be selected simultaneously outside of editing mode. When the value of this property is YES, each row that is tapped acquires a selected appearance. Tapping the row again removes the selected appearance. If you access indexPathsForSelectedRows, you can get the index paths that identify the selected rows. | ||
*/ | ||
@property (nonatomic) BOOL allowsMultipleSelection; |
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.
Add assign
* A Boolean value that controls whether users can select more than one cell simultaneously in editing mode. | ||
* The default value of this property is NO. If you set it to YES, check marks appear next to selected rows in editing mode. In addition, UITableView does not query for editing styles when it goes into editing mode. If you access indexPathsForSelectedRows, you can get the index paths that identify the selected rows. | ||
*/ | ||
@property (nonatomic) BOOL allowsMultipleSelectionDuringEditing; |
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.
Add assign
@property (nonatomic) BOOL allowsSelection; | ||
@property (nonatomic) BOOL allowsSelectionDuringEditing; | ||
@property (nonatomic) BOOL allowsMultipleSelection; | ||
@property (nonatomic) BOOL allowsMultipleSelectionDuringEditing; |
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.
Please add assign
to all of them.
[self.view deselectRowAtIndexPath:indexPath animated:animated]; | ||
} | ||
|
||
#pragma mark - Querying Data |
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.
Add white space below
@@ -222,27 +222,60 @@ - (void)testSelection | |||
|
|||
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:0]; | |||
ASCellNode *node = [testController.collectionView nodeForItemAtIndexPath:indexPath]; | |||
|
|||
|
|||
int setSelectedCount = 0; |
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.
Use NSInteger
Nice! Thanks @george-gw! |
refs #2450
ASCollectionNode:
Unsure if you think the following are needed, but I added them just in case.
ASTableNode:
Unsure if you think the following are needed, but I added them just in case.