Chromium Code Reviews| Index: ios/chrome/browser/ui/suggestions/suggestions_view_controller.mm |
| diff --git a/ios/chrome/browser/ui/suggestions/suggestions_view_controller.mm b/ios/chrome/browser/ui/suggestions/suggestions_view_controller.mm |
| index a27da97a063afef0786224ca5511cfd72ae5fbe0..d510898040857f1d71cf86782c628982735a1539 100644 |
| --- a/ios/chrome/browser/ui/suggestions/suggestions_view_controller.mm |
| +++ b/ios/chrome/browser/ui/suggestions/suggestions_view_controller.mm |
| @@ -4,6 +4,7 @@ |
| #import "ios/chrome/browser/ui/suggestions/suggestions_view_controller.h" |
| +#include "base/mac/foundation_util.h" |
| #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h" |
| #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
| #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| @@ -15,10 +16,18 @@ |
| #error "This file requires ARC support." |
| #endif |
| +typedef void (^ExpandableCellInteraction)(SuggestionsExpandableItem*, |
| + SuggestionsExpandableCell*); |
| + |
| @interface SuggestionsViewController ()<SuggestionsItemActions> |
| @property(nonatomic, strong) SuggestionsCollectionUpdater* collectionUpdater; |
| +// Applies |interaction| to the item corresponding to |cell| if it is a |
| +// SuggestionsExpandableCell. |
| +- (void)interact:(ExpandableCellInteraction)interaction |
| + withCell:(UICollectionViewCell*)cell; |
| + |
| @end |
| @implementation SuggestionsViewController |
| @@ -54,6 +63,24 @@ |
| forItem:item]; |
| } |
| +#pragma mark - SuggestionsExpandableCellAudience |
| + |
| +- (void)retractCell:(UICollectionViewCell*)cell { |
| + [self interact:^(SuggestionsExpandableItem* item, |
|
lpromero
2017/01/13 17:35:48
See streamlined code in my comment above.
gambard
2017/01/16 09:50:39
Done.
|
| + SuggestionsExpandableCell* expandableCell) { |
| + [item retract:expandableCell]; |
| + } |
| + withCell:cell]; |
| +} |
| + |
| +- (void)expandCell:(UICollectionViewCell*)cell { |
| + [self interact:^(SuggestionsExpandableItem* item, |
| + SuggestionsExpandableCell* expandableCell) { |
| + [item expand:expandableCell]; |
| + } |
| + withCell:cell]; |
| +} |
| + |
| #pragma mark - SuggestionsItemActions |
| - (void)addNewItem:(id)sender { |
| @@ -70,4 +97,30 @@ |
| toSection:inputSection]; |
| } |
| +#pragma mark - Private |
| + |
| +- (void)interact:(ExpandableCellInteraction)interaction |
| + withCell:(UICollectionViewCell*)cell { |
| + if (!interaction) { |
| + return; |
| + } |
| + NSIndexPath* indexPath = [self.collectionView indexPathForCell:cell]; |
| + CollectionViewItem* item = |
| + [self.collectionViewModel itemAtIndexPath:indexPath]; |
| + if ([item isKindOfClass:[SuggestionsExpandableItem class]]) { |
| + SuggestionsExpandableItem* expandableItem = |
| + base::mac::ObjCCast<SuggestionsExpandableItem>(item); |
| + SuggestionsExpandableCell* expandableCell = |
| + base::mac::ObjCCast<SuggestionsExpandableCell>(cell); |
| + |
| + interaction(expandableItem, expandableCell); |
| + |
| + [UIView |
| + animateWithDuration:1 |
| + animations:^{ |
| + [self.collectionView.collectionViewLayout invalidateLayout]; |
| + }]; |
| + } |
| +} |
| + |
| @end |