Commit 0bde49f3 authored by Rohit Rao's avatar Rohit Rao Committed by Commit Bot

[ios] Adds a dimmingShield to TableViewPresentationController.

This shield will dismiss the presented view controller when tapped.

BUG=805154
TEST=With UIRefreshPhase1 enabled on tablet, tapping outside of the Recent Tabs view should dismiss Recent Tabs.

Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I5f723382e5e048078461622b23247d5bbfa24644
Reviewed-on: https://chromium-review.googlesource.com/1007766Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Commit-Queue: Rohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549951}
parent 19a69a13
...@@ -35,8 +35,20 @@ const CGFloat kTableViewMaxWidth = 414.0; ...@@ -35,8 +35,20 @@ const CGFloat kTableViewMaxWidth = 414.0;
@interface TableViewPresentationController () @interface TableViewPresentationController ()
// A view which prevents touches from reaching views below this controller's
// |containerView|. This view is normally clear and dismisses the presented
// view controller when tapped, but can optionally act as a dimming view and
// ignore touches.
@property(nonatomic, readwrite, strong) UIView* dimmingShield;
// A container view for |tableViewContainer| and |shadowImage|.
@property(nonatomic, readwrite, strong) UIView* shadowContainer; @property(nonatomic, readwrite, strong) UIView* shadowContainer;
// Draws a shadow to visually separate the contents of |tableViewContainer| from
// the views below.
@property(nonatomic, readwrite, strong) UIImageView* shadowImage; @property(nonatomic, readwrite, strong) UIImageView* shadowImage;
// Acts as a container for the presented view controller's view.
@property(nonatomic, readwrite, strong) UIView* tableViewContainer; @property(nonatomic, readwrite, strong) UIView* tableViewContainer;
// Cleans up and removes any views that are managed by this controller. // Cleans up and removes any views that are managed by this controller.
...@@ -45,6 +57,7 @@ const CGFloat kTableViewMaxWidth = 414.0; ...@@ -45,6 +57,7 @@ const CGFloat kTableViewMaxWidth = 414.0;
@end @end
@implementation TableViewPresentationController @implementation TableViewPresentationController
@synthesize dimmingShield = _dimmingShield;
@synthesize shadowContainer = _shadowContainer; @synthesize shadowContainer = _shadowContainer;
@synthesize shadowImage = _shadowImage; @synthesize shadowImage = _shadowImage;
@synthesize tableViewContainer = _tableViewContainer; @synthesize tableViewContainer = _tableViewContainer;
...@@ -70,8 +83,18 @@ const CGFloat kTableViewMaxWidth = 414.0; ...@@ -70,8 +83,18 @@ const CGFloat kTableViewMaxWidth = 414.0;
} }
- (void)presentationTransitionWillBegin { - (void)presentationTransitionWillBegin {
self.shadowContainer = [[UIView alloc] init]; // The dimming view is added first, so that all other views are layered on top
// of it.
self.dimmingShield = [[UIView alloc] init];
self.dimmingShield.backgroundColor = [UIColor clearColor];
self.dimmingShield.frame = self.containerView.bounds;
[self.containerView addSubview:self.dimmingShield];
[self.dimmingShield
addGestureRecognizer:[[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleShieldTap)]];
self.shadowContainer = [[UIView alloc] init];
self.shadowImage = self.shadowImage =
[[UIImageView alloc] initWithImage:StretchableImageNamed(@"menu_shadow")]; [[UIImageView alloc] initWithImage:StretchableImageNamed(@"menu_shadow")];
self.shadowImage.translatesAutoresizingMaskIntoConstraints = NO; self.shadowImage.translatesAutoresizingMaskIntoConstraints = NO;
...@@ -136,6 +159,7 @@ const CGFloat kTableViewMaxWidth = 414.0; ...@@ -136,6 +159,7 @@ const CGFloat kTableViewMaxWidth = 414.0;
} }
- (void)containerViewWillLayoutSubviews { - (void)containerViewWillLayoutSubviews {
self.dimmingShield.frame = self.containerView.bounds;
self.shadowContainer.frame = [self frameOfPresentedViewInContainerView]; self.shadowContainer.frame = [self frameOfPresentedViewInContainerView];
} }
...@@ -148,6 +172,15 @@ const CGFloat kTableViewMaxWidth = 414.0; ...@@ -148,6 +172,15 @@ const CGFloat kTableViewMaxWidth = 414.0;
self.shadowImage = nil; self.shadowImage = nil;
[self.shadowContainer removeFromSuperview]; [self.shadowContainer removeFromSuperview];
self.shadowContainer = nil; self.shadowContainer = nil;
[self.dimmingShield removeFromSuperview];
self.dimmingShield = nil;
}
#pragma mark - Actions
- (void)handleShieldTap {
[self.presentedViewController dismissViewControllerAnimated:YES
completion:nil];
} }
#pragma mark - Adaptivity #pragma mark - Adaptivity
......
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