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 @@ ...@@ -12,8 +12,19 @@
// InfobarBanner Presentation Controller. // InfobarBanner Presentation Controller.
@interface InfobarBannerPresentationController : UIPresentationController @interface InfobarBannerPresentationController : UIPresentationController
// Delegate used to position the InfobarBanner. // Designated initializer. |bannerPositioner| is used to position the
@property(nonatomic, assign) id<InfobarBannerPositioner> bannerPositioner; // 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 @end
......
...@@ -20,8 +20,26 @@ const CGFloat kContainerMaxWidth = 398; ...@@ -20,8 +20,26 @@ const CGFloat kContainerMaxWidth = 398;
const CGFloat kContainerMaxHeight = 230; const CGFloat kContainerMaxHeight = 230;
} }
@interface InfobarBannerPresentationController ()
// Delegate used to position the InfobarBanner.
@property(nonatomic, weak) id<InfobarBannerPositioner> bannerPositioner;
@end
@implementation InfobarBannerPresentationController @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 { - (void)presentationTransitionWillBegin {
self.containerView.frame = [self viewForPresentedView].frame; self.containerView.frame = [self viewForPresentedView].frame;
} }
...@@ -29,11 +47,11 @@ const CGFloat kContainerMaxHeight = 230; ...@@ -29,11 +47,11 @@ const CGFloat kContainerMaxHeight = 230;
- (void)containerViewWillLayoutSubviews { - (void)containerViewWillLayoutSubviews {
self.containerView.frame = [self viewForPresentedView].frame; self.containerView.frame = [self viewForPresentedView].frame;
self.presentedView.frame = [self viewForPresentedView].bounds; self.presentedView.frame = [self viewForPresentedView].bounds;
[super containerViewWillLayoutSubviews];
} }
- (UIView*)viewForPresentedView { - (UIView*)viewForPresentedView {
DCHECK(self.bannerPositioner); UIWindow* window = self.containerView.window;
UIWindow* window = UIApplication.sharedApplication.keyWindow;
// Calculate the Banner container width. // Calculate the Banner container width.
CGFloat safeAreaWidth = CGRectGetWidth(window.bounds); CGFloat safeAreaWidth = CGRectGetWidth(window.bounds);
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
InfobarBannerInteractionDelegate> InfobarBannerInteractionDelegate>
// Delegate used to position the InfobarBanner. // 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 // Completes the banner presentation if taking place. This will stop the banner
// animation and move it to the presenting ViewController hierarchy. // animation and move it to the presenting ViewController hierarchy.
......
...@@ -31,8 +31,8 @@ ...@@ -31,8 +31,8 @@
InfobarBannerPresentationController* presentationController = InfobarBannerPresentationController* presentationController =
[[InfobarBannerPresentationController alloc] [[InfobarBannerPresentationController alloc]
initWithPresentedViewController:presented initWithPresentedViewController:presented
presentingViewController:presenting]; presentingViewController:presenting
presentationController.bannerPositioner = self.bannerPositioner; bannerPositioner:self.bannerPositioner];
return presentationController; return presentationController;
} }
......
...@@ -12,8 +12,18 @@ ...@@ -12,8 +12,18 @@
// PresentationController for the ModalInfobar. // PresentationController for the ModalInfobar.
@interface InfobarModalPresentationController : UIPresentationController @interface InfobarModalPresentationController : UIPresentationController
// Delegate used to position the ModalInfobar. // Designated initializer. |modalPositioner| is used to position the
@property(nonatomic, assign) id<InfobarModalPositioner> modalPositioner; // 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 @end
......
...@@ -22,8 +22,26 @@ const CGFloat kPresentedViewMaxWidth = 394.0; ...@@ -22,8 +22,26 @@ const CGFloat kPresentedViewMaxWidth = 394.0;
const CGFloat kContainerCornerRadius = 13.0; const CGFloat kContainerCornerRadius = 13.0;
} // namespace } // namespace
@interface InfobarModalPresentationController ()
// Delegate used to position the ModalInfobar.
@property(nonatomic, weak) id<InfobarModalPositioner> modalPositioner;
@end
@implementation InfobarModalPresentationController @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 { - (void)presentationTransitionWillBegin {
// Add a gesture recognizer to endEditing (thus hiding the keyboard) if a user // Add a gesture recognizer to endEditing (thus hiding the keyboard) if a user
// taps outside the keyboard while one its being presented. Set // taps outside the keyboard while one its being presented. Set
...@@ -45,10 +63,11 @@ const CGFloat kContainerCornerRadius = 13.0; ...@@ -45,10 +63,11 @@ const CGFloat kContainerCornerRadius = 13.0;
self.presentedView.clipsToBounds = YES; self.presentedView.clipsToBounds = YES;
self.containerView.backgroundColor = self.containerView.backgroundColor =
[UIColor colorNamed:kScrimBackgroundColor]; [UIColor colorNamed:kScrimBackgroundColor];
[super containerViewWillLayoutSubviews];
} }
- (CGRect)frameForPresentedView { - (CGRect)frameForPresentedView {
DCHECK(self.modalPositioner);
CGRect safeAreaBounds = self.containerView.safeAreaLayoutGuide.layoutFrame; CGRect safeAreaBounds = self.containerView.safeAreaLayoutGuide.layoutFrame;
CGFloat safeAreaWidth = CGRectGetWidth(safeAreaBounds); CGFloat safeAreaWidth = CGRectGetWidth(safeAreaBounds);
CGFloat safeAreaHeight = CGRectGetHeight(safeAreaBounds); CGFloat safeAreaHeight = CGRectGetHeight(safeAreaBounds);
......
...@@ -28,7 +28,7 @@ typedef NS_ENUM(NSInteger, InfobarModalTransition) { ...@@ -28,7 +28,7 @@ typedef NS_ENUM(NSInteger, InfobarModalTransition) {
@property(nonatomic, assign, readonly) InfobarModalTransition transitionMode; @property(nonatomic, assign, readonly) InfobarModalTransition transitionMode;
// Delegate used to position the ModalInfobar. // Delegate used to position the ModalInfobar.
@property(nonatomic, assign) id<InfobarModalPositioner> modalPositioner; @property(nonatomic, weak) id<InfobarModalPositioner> modalPositioner;
@end @end
......
...@@ -32,8 +32,8 @@ ...@@ -32,8 +32,8 @@
InfobarModalPresentationController* presentationController = InfobarModalPresentationController* presentationController =
[[InfobarModalPresentationController alloc] [[InfobarModalPresentationController alloc]
initWithPresentedViewController:presented initWithPresentedViewController:presented
presentingViewController:presenting]; presentingViewController:presenting
presentationController.modalPositioner = self.modalPositioner; modalPositioner:self.modalPositioner];
return presentationController; 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