Commit 43535078 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Adds a highlight tap animation to TableViewTextHeaderFooterView

Bug: 822987
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I7aa275e08846b1ea9b067de343f6a631a56db566
Reviewed-on: https://chromium-review.googlesource.com/972163
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546154}
parent 1206fd3a
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "ios/chrome/browser/ui/ntp/recent_tabs/recent_tabs_table_view_controller.h" #import "ios/chrome/browser/ui/ntp/recent_tabs/recent_tabs_table_view_controller.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/foundation_util.h"
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h" #include "base/metrics/user_metrics_action.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
...@@ -769,6 +770,15 @@ const int kRelativeTimeMaxHours = 4; ...@@ -769,6 +770,15 @@ const int kRelativeTimeMaxHours = 4;
if (tapGesture.state == UIGestureRecognizerStateEnded) { if (tapGesture.state == UIGestureRecognizerStateEnded) {
[self toggleExpansionOfSectionIdentifier: [self toggleExpansionOfSectionIdentifier:
self.lastTappedHeaderSectionIdentifier]; self.lastTappedHeaderSectionIdentifier];
// Highlight the section header being tapped.
NSInteger section = [self.tableViewModel
sectionForSectionIdentifier:self.lastTappedHeaderSectionIdentifier];
UITableViewHeaderFooterView* headerView =
[self.tableView headerViewForSection:section];
TableViewTextHeaderFooterView* headerTextView =
base::mac::ObjCCastStrict<TableViewTextHeaderFooterView>(headerView);
[headerTextView animateHighlight];
} }
} }
...@@ -817,6 +827,15 @@ const int kRelativeTimeMaxHours = 4; ...@@ -817,6 +827,15 @@ const int kRelativeTimeMaxHours = 4;
return; return;
} }
// Highlight the section header being long pressed.
NSInteger section = [self.tableViewModel
sectionForSectionIdentifier:self.lastTappedHeaderSectionIdentifier];
UITableViewHeaderFooterView* headerView =
[self.tableView headerViewForSection:section];
TableViewTextHeaderFooterView* headerTextView =
base::mac::ObjCCastStrict<TableViewTextHeaderFooterView>(headerView);
[headerTextView animateHighlight];
web::ContextMenuParams params; web::ContextMenuParams params;
// Get view coordinates in local space. // Get view coordinates in local space.
CGPoint viewCoordinate = [longPressGesture locationInView:self.tableView]; CGPoint viewCoordinate = [longPressGesture locationInView:self.tableView];
......
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
// UITableViewHeaderFooterView that displays a text label. // UITableViewHeaderFooterView that displays a text label.
@interface TableViewTextHeaderFooterView : UITableViewHeaderFooterView @interface TableViewTextHeaderFooterView : UITableViewHeaderFooterView
@property(nonatomic, readwrite, strong) UILabel* subtitleLabel; @property(nonatomic, readwrite, strong) UILabel* subtitleLabel;
// Animates a change in the backgroundView color and then changes it back to the
// original backGround color in order to simulate a selection highlight.
- (void)animateHighlight;
@end @end
#endif // IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_TEXT_HEADER_FOOTER_ITEM_H_ #endif // IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_TEXT_HEADER_FOOTER_ITEM_H_
...@@ -48,7 +48,13 @@ const CGFloat kVerticalSpacing = 2.0; ...@@ -48,7 +48,13 @@ const CGFloat kVerticalSpacing = 2.0;
#pragma mark - TableViewTextHeaderFooter #pragma mark - TableViewTextHeaderFooter
@interface TableViewTextHeaderFooterView ()
// Animator that handles all cell animations.
@property(strong, nonatomic) UIViewPropertyAnimator* cellAnimator;
@end
@implementation TableViewTextHeaderFooterView @implementation TableViewTextHeaderFooterView
@synthesize cellAnimator = _cellAnimator;
@synthesize subtitleLabel = _subtitleLabel; @synthesize subtitleLabel = _subtitleLabel;
@synthesize textLabel = _textLabel; @synthesize textLabel = _textLabel;
...@@ -108,4 +114,26 @@ const CGFloat kVerticalSpacing = 2.0; ...@@ -108,4 +114,26 @@ const CGFloat kVerticalSpacing = 2.0;
return self; return self;
} }
- (void)animateHighlight {
UIColor* originalBackgroundColor = self.contentView.backgroundColor;
self.cellAnimator = [[UIViewPropertyAnimator alloc]
initWithDuration:0.15
curve:UIViewAnimationCurveLinear
animations:^{
self.contentView.backgroundColor =
[[UIColor lightGrayColor] colorWithAlphaComponent:0.5];
}];
__weak TableViewTextHeaderFooterView* weakSelf = self;
[self.cellAnimator addCompletion:^(UIViewAnimatingPosition finalPosition) {
weakSelf.contentView.backgroundColor = originalBackgroundColor;
}];
[self.cellAnimator startAnimation];
}
- (void)prepareForReuse {
[super prepareForReuse];
if (self.cellAnimator.isRunning)
[self.cellAnimator stopAnimation:YES];
}
@end @end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment