Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Added selection API to ASTableNode and ASCollectionNode #2453

Merged
merged 4 commits into from
Oct 24, 2016

Conversation

george-gw
Copy link
Contributor

@george-gw george-gw commented Oct 21, 2016

refs #2450

ASCollectionNode:

  • [ASCollectionNode selectItemAtIndexPath:animated:scrollPosition:]
  • [ASCollectionNode deselectItemAtIndexPath:animated:]

Unsure if you think the following are needed, but I added them just in case.

  • BOOL allowsSelection -> collectionView.allowsSelection
  • BOOL allowsMultipleSelection -> collectionView.allowsMultipleSelection

ASTableNode:

  • [ASTableNode selectRowAtIndexPath:animated:scrollPosition:]
  • -[ASTableNode deselectRowAtIndexPath:animated:]

Unsure if you think the following are needed, but I added them just in case.

  • BOOL allowsSelection -> collectionView.allowsSelection
  • BOOL allowsSelectionDuringEditing -> collectionView.allowsSelectionDuringEditing
  • BOOL allowsMultipleSelection -> collectionView.allowsMultipleSelection
  • BOOL allowsMultipleSelectionDuringEditing -> collectionView.allowsMultipleSelectionDuringEditing

@george-gw george-gw changed the title Added selection API to ASTableNode and ASCollectionNode (#2450) Added selection API to ASTableNode and ASCollectionNode Oct 21, 2016
_pendingState.allowsMultipleSelection = allowsMultipleSelection;
} else {
ASDisplayNodeAssert([self isNodeLoaded], @"ASCollectionNode should be loaded if pendingState doesn't exist");
self.view.allowsSelection = allowsMultipleSelection;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

Copy link
Contributor Author

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;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

Copy link
Contributor

@Adlai-Holler Adlai-Holler left a 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");
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@Adlai-Holler
Copy link
Contributor

test this please

Added asserts for main thread.
Updated ASCollectionViewTests for multiple selections for nodes.
@george-gw
Copy link
Contributor Author

george-gw commented Oct 22, 2016

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add assign

Copy link
Contributor Author

@george-gw george-gw Oct 22, 2016

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;
Copy link
Contributor

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
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

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
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use NSInteger

@Adlai-Holler
Copy link
Contributor

Nice! Thanks @george-gw!

@Adlai-Holler Adlai-Holler merged commit 3638fef into facebookarchive:master Oct 24, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants