Commit 56c0277e authored by sczs's avatar sczs Committed by Commit Bot

[ios] Refactors Messages PresentationControllers

- Changes both positioners to weak from assign.
- Removes a DCHECK since it seems that the positioner can be niled
in certain conditions like shutdown, in order to make sure these are
set they are now part of the initializer.
- Adds a containerViewWillLayoutSubviews super call to both positioners.

Bug: 1034635
Change-Id: Iee46b2b2313831a289100f47e3ef8a96c4e20dcb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2067382Reviewed-by: default avatarChris Lu <thegreenfrog@chromium.org>
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743310}
parent 22b25dd3
......@@ -12,8 +12,19 @@
// InfobarBanner Presentation Controller.
@interface InfobarBannerPresentationController : UIPresentationController
// Delegate used to position the InfobarBanner.
@property(nonatomic, assign) id<InfobarBannerPositioner> bannerPositioner;
// Designated initializer. |bannerPositioner| is used to position the
// InfobarBanner, it can't be nil.
- (instancetype)
initWithPresentedViewController:(UIViewController*)presentedViewController
presentingViewController:(UIViewController*)presentingViewController
bannerPositioner:
(id<InfobarBannerPositioner>)bannerPositioner
NS_DESIGNATED_INITIALIZER;
- (instancetype)
initWithPresentedViewController:(UIViewController*)presentedViewController
presentingViewController:(UIViewController*)presentingViewController
NS_UNAVAILABLE;
@end
......
......@@ -20,8 +20,26 @@ const CGFloat kContainerMaxWidth = 398;
const CGFloat kContainerMaxHeight = 230;
}
@interface InfobarBannerPresentationController ()
// Delegate used to position the InfobarBanner.
@property(nonatomic, weak) id<InfobarBannerPositioner> bannerPositioner;
@end
@implementation InfobarBannerPresentationController
- (instancetype)
initWithPresentedViewController:(UIViewController*)presentedViewController
presentingViewController:(UIViewController*)presentingViewController
bannerPositioner:
(id<InfobarBannerPositioner>)bannerPositioner {
self = [super initWithPresentedViewController:presentedViewController
presentingViewController:presentingViewController];
if (self) {
_bannerPositioner = bannerPositioner;
}
return self;
}
- (void)presentationTransitionWillBegin {
self.containerView.frame = [self viewForPresentedView].frame;
}
......@@ -29,11 +47,11 @@ const CGFloat kContainerMaxHeight = 230;
- (void)containerViewWillLayoutSubviews {
self.containerView.frame = [self viewForPresentedView].frame;
self.presentedView.frame = [self viewForPresentedView].bounds;
[super containerViewWillLayoutSubviews];
}
- (UIView*)viewForPresentedView {
DCHECK(self.bannerPositioner);
UIWindow* window = UIApplication.sharedApplication.keyWindow;
UIWindow* window = self.containerView.window;
// Calculate the Banner container width.
CGFloat safeAreaWidth = CGRectGetWidth(window.bounds);
......
......@@ -17,7 +17,7 @@
InfobarBannerInteractionDelegate>
// Delegate used to position the InfobarBanner.
@property(nonatomic, assign) id<InfobarBannerPositioner> bannerPositioner;
@property(nonatomic, weak) id<InfobarBannerPositioner> bannerPositioner;
// Completes the banner presentation if taking place. This will stop the banner
// animation and move it to the presenting ViewController hierarchy.
......
......@@ -31,8 +31,8 @@
InfobarBannerPresentationController* presentationController =
[[InfobarBannerPresentationController alloc]
initWithPresentedViewController:presented
presentingViewController:presenting];
presentationController.bannerPositioner = self.bannerPositioner;
presentingViewController:presenting
bannerPositioner:self.bannerPositioner];
return presentationController;
}
......
......@@ -12,8 +12,18 @@
// PresentationController for the ModalInfobar.
@interface InfobarModalPresentationController : UIPresentationController
// Delegate used to position the ModalInfobar.
@property(nonatomic, assign) id<InfobarModalPositioner> modalPositioner;
// Designated initializer. |modalPositioner| is used to position the
// ModalInfobar, it can't be nil.
- (instancetype)
initWithPresentedViewController:(UIViewController*)presentedViewController
presentingViewController:(UIViewController*)presentingViewController
modalPositioner:(id<InfobarModalPositioner>)modalPositioner
NS_DESIGNATED_INITIALIZER;
- (instancetype)
initWithPresentedViewController:(UIViewController*)presentedViewController
presentingViewController:(UIViewController*)presentingViewController
NS_UNAVAILABLE;
@end
......
......@@ -22,8 +22,26 @@ const CGFloat kPresentedViewMaxWidth = 394.0;
const CGFloat kContainerCornerRadius = 13.0;
} // namespace
@interface InfobarModalPresentationController ()
// Delegate used to position the ModalInfobar.
@property(nonatomic, weak) id<InfobarModalPositioner> modalPositioner;
@end
@implementation InfobarModalPresentationController
- (instancetype)
initWithPresentedViewController:(UIViewController*)presentedViewController
presentingViewController:(UIViewController*)presentingViewController
modalPositioner:
(id<InfobarModalPositioner>)modalPositioner {
self = [super initWithPresentedViewController:presentedViewController
presentingViewController:presentingViewController];
if (self) {
_modalPositioner = modalPositioner;
}
return self;
}
- (void)presentationTransitionWillBegin {
// Add a gesture recognizer to endEditing (thus hiding the keyboard) if a user
// taps outside the keyboard while one its being presented. Set
......@@ -45,10 +63,11 @@ const CGFloat kContainerCornerRadius = 13.0;
self.presentedView.clipsToBounds = YES;
self.containerView.backgroundColor =
[UIColor colorNamed:kScrimBackgroundColor];
[super containerViewWillLayoutSubviews];
}
- (CGRect)frameForPresentedView {
DCHECK(self.modalPositioner);
CGRect safeAreaBounds = self.containerView.safeAreaLayoutGuide.layoutFrame;
CGFloat safeAreaWidth = CGRectGetWidth(safeAreaBounds);
CGFloat safeAreaHeight = CGRectGetHeight(safeAreaBounds);
......
......@@ -28,7 +28,7 @@ typedef NS_ENUM(NSInteger, InfobarModalTransition) {
@property(nonatomic, assign, readonly) InfobarModalTransition transitionMode;
// Delegate used to position the ModalInfobar.
@property(nonatomic, assign) id<InfobarModalPositioner> modalPositioner;
@property(nonatomic, weak) id<InfobarModalPositioner> modalPositioner;
@end
......
......@@ -32,8 +32,8 @@
InfobarModalPresentationController* presentationController =
[[InfobarModalPresentationController alloc]
initWithPresentedViewController:presented
presentingViewController:presenting];
presentationController.modalPositioner = self.modalPositioner;
presentingViewController:presenting
modalPositioner:self.modalPositioner];
return presentationController;
}
......
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