Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(443)

Unified Diff: ios/chrome/browser/ui/suggestions/suggestions_view_controller.mm

Issue 2625693002: Suggestions UI - expandable item (Closed)
Patch Set: Address comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/ui/suggestions/suggestions_view_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..84a8ef635f6a41f86dd66c6155c26715db906d38 100644
--- a/ios/chrome/browser/ui/suggestions/suggestions_view_controller.mm
+++ b/ios/chrome/browser/ui/suggestions/suggestions_view_controller.mm
@@ -4,9 +4,11 @@
#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"
+#import "ios/chrome/browser/ui/suggestions/expandable_item.h"
#import "ios/chrome/browser/ui/suggestions/suggestions_collection_updater.h"
#import "ios/chrome/browser/ui/suggestions/suggestions_commands.h"
#import "ios/chrome/browser/ui/suggestions/suggestions_item_actions.h"
@@ -15,10 +17,18 @@
#error "This file requires ARC support."
#endif
+namespace {
+const NSTimeInterval kAnimationDuration = 0.35;
+} // namespace
+
@interface SuggestionsViewController ()<SuggestionsItemActions>
@property(nonatomic, strong) SuggestionsCollectionUpdater* collectionUpdater;
+// Expand or collapse the |cell|, if it is a SuggestionsExpandableCell,
+// according to |expand|.
+- (void)expand:(BOOL)expand cell:(UICollectionViewCell*)cell;
+
@end
@implementation SuggestionsViewController
@@ -54,6 +64,16 @@
forItem:item];
}
+#pragma mark - SuggestionsExpandableCellDelegate
+
+- (void)collapseCell:(UICollectionViewCell*)cell {
+ [self expand:NO cell:cell];
+}
+
+- (void)expandCell:(UICollectionViewCell*)cell {
+ [self expand:YES cell:cell];
+}
+
#pragma mark - SuggestionsItemActions
- (void)addNewItem:(id)sender {
@@ -70,4 +90,29 @@
toSection:inputSection];
}
+#pragma mark - Private
+
+- (void)expand:(BOOL)expand cell:(UICollectionViewCell*)cell {
+ NSIndexPath* indexPath = [self.collectionView indexPathForCell:cell];
+ CollectionViewItem* item =
+ [self.collectionViewModel itemAtIndexPath:indexPath];
+ if ([item conformsToProtocol:@protocol(SuggestionsExpandableArticle)]) {
+ id<SuggestionsExpandableArticle> expandableItem =
+ (id<SuggestionsExpandableArticle>)item;
+
+ NSInteger sectionIdentifier = [self.collectionViewModel
+ sectionIdentifierForSection:indexPath.section];
+
+ expandableItem.expanded = expand;
+ [self reconfigureCellsForItems:@[ item ]
+ inSectionWithIdentifier:sectionIdentifier];
+
+ [UIView
+ animateWithDuration:kAnimationDuration
+ animations:^{
+ [self.collectionView.collectionViewLayout invalidateLayout];
+ }];
+ }
+}
+
@end
« no previous file with comments | « ios/chrome/browser/ui/suggestions/suggestions_view_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698