Commit 3b0649bf authored by Robbie Gibson's avatar Robbie Gibson Committed by Commit Bot

[iOS] Add skeleton of Text Zoom UI

This adds a simple UI for text zoom (just the done button). The more
important contribution is that now, BVC will check which feature is
active, text zoom or find in page, and if something asks it to display
the other, it first dismisses the shown one.

Bug: 1028938
Change-Id: I576a096a635e0736f70e853f3c78e5459d7f4b78
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1946481
Commit-Queue: Robbie Gibson <rkgibson@google.com>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#730153}
parent c369c7ae
......@@ -139,6 +139,8 @@ source_set("browser_view") {
"//ios/chrome/browser/ui/tabs",
"//ios/chrome/browser/ui/tabs:coordinator",
"//ios/chrome/browser/ui/tabs/requirements",
"//ios/chrome/browser/ui/text_zoom",
"//ios/chrome/browser/ui/text_zoom:text_zoom_ui",
"//ios/chrome/browser/ui/toolbar",
"//ios/chrome/browser/ui/toolbar:toolbar_ui",
"//ios/chrome/browser/ui/toolbar/accessory",
......
......@@ -129,6 +129,8 @@
#import "ios/chrome/browser/ui/tabs/requirements/tab_strip_presentation.h"
#import "ios/chrome/browser/ui/tabs/switch_to_tab_animation_view.h"
#import "ios/chrome/browser/ui/tabs/tab_strip_legacy_coordinator.h"
#import "ios/chrome/browser/ui/text_zoom/text_zoom_coordinator.h"
#import "ios/chrome/browser/ui/text_zoom/text_zoom_view_controller.h"
#import "ios/chrome/browser/ui/toolbar/accessory/toolbar_accessory_coordinator_delegate.h"
#import "ios/chrome/browser/ui/toolbar/accessory/toolbar_accessory_presenter.h"
#import "ios/chrome/browser/ui/toolbar/adaptive_toolbar_coordinator.h"
......@@ -558,6 +560,11 @@ NSString* const kBrowserViewControllerSnackbarCategory =
// Coordinator for find in page.
@property(nonatomic, strong) FindBarCoordinator* findBarCoordinator;
// Coordinator for text zoom.
@property(nonatomic, strong) TextZoomCoordinator* textZoomCoordinator;
@property(nonatomic, weak) ChromeCoordinator* nextToolbarCoordinator;
@property(nonatomic, strong) BubblePresenter* bubblePresenter;
// Primary toolbar.
......@@ -1011,7 +1018,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
.viewController.view
headerBehaviour:Hideable]];
}
if (self.toolbarAccessoryPresenter.backgroundView) {
if (self.toolbarAccessoryPresenter.isPresenting) {
[results addObject:[HeaderDefinition
definitionWithView:self.toolbarAccessoryPresenter
.backgroundView
......@@ -1269,7 +1276,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
auto* findHelper = FindTabHelper::FromWebState(webState);
if (findHelper) {
findHelper->StopFinding(^{
[self.findBarCoordinator hideFindBarWithAnimation:YES];
[self.findBarCoordinator stop];
});
}
}
......@@ -1667,7 +1674,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
// updateToobar];
if (ShouldShowCompactToolbar(previousTraitCollection) !=
ShouldShowCompactToolbar()) {
[self.findBarCoordinator hideFindBarWithAnimation:NO];
[self.findBarCoordinator stop];
}
// Update the toolbar visibility.
......@@ -2360,7 +2367,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
if (!self.inNewTabAnimation) {
// Hide findbar. |updateToolbar| will restore the findbar later.
[self.findBarCoordinator hideFindBarWithAnimation:NO];
[self.findBarCoordinator stop];
// Make new content visible, resizing it first as the orientation may
// have changed from the last time it was displayed.
......@@ -2452,7 +2459,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
auto* findHelper = FindTabHelper::FromWebState(webState);
if (findHelper && findHelper->IsFindUIActive()) {
[self.findBarCoordinator showFindBarAnimated:NO];
[self.findBarCoordinator start];
}
BOOL hideToolbar = NO;
......@@ -4045,30 +4052,27 @@ NSString* const kBrowserViewControllerSnackbarCategory =
if (!self.canShowFindBar)
return;
if (!self.toolbarAccessoryPresenter) {
self.toolbarAccessoryPresenter =
[[ToolbarAccessoryPresenter alloc] initWithIsIncognito:_isOffTheRecord];
self.toolbarAccessoryPresenter.baseViewController = self;
if (self.toolbarAccessoryPresenter.isPresenting) {
self.nextToolbarCoordinator = self.findBarCoordinator;
[self hideTextZoom];
return;
}
if (!self.findBarCoordinator) {
self.findBarCoordinator =
[[FindBarCoordinator alloc] initWithBaseViewController:self
browser:self.browser];
self.findBarCoordinator.presenter = self.toolbarAccessoryPresenter;
self.findBarCoordinator.delegate = self;
[self.findBarCoordinator start];
}
[self.findBarCoordinator startFindInPage];
[self.findBarCoordinator start];
}
- (void)closeFindInPage {
__weak BrowserViewController* weakSelf = self;
if (self.currentWebState) {
FindTabHelper::FromWebState(self.currentWebState)->StopFinding(^{
[weakSelf.findBarCoordinator hideFindBarWithAnimation:YES];
});
FindTabHelper* findTabHelper =
FindTabHelper::FromWebState(self.currentWebState);
if (findTabHelper->IsFindUIActive()) {
findTabHelper->StopFinding(^{
[weakSelf.findBarCoordinator stop];
});
} else {
[self.findBarCoordinator stop];
}
}
}
......@@ -4206,6 +4210,20 @@ NSString* const kBrowserViewControllerSnackbarCategory =
}
}
- (void)showTextZoom {
if (self.toolbarAccessoryPresenter.isPresenting) {
self.nextToolbarCoordinator = self.textZoomCoordinator;
[self closeFindInPage];
return;
}
[self.textZoomCoordinator start];
}
- (void)hideTextZoom {
[self.textZoomCoordinator stop];
}
#pragma mark - BrowserCommands helpers
// Reloads the original url of the last non-redirect item (including non-history
......@@ -4261,7 +4279,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
return;
// Remove the find bar for now.
[self.findBarCoordinator hideFindBarWithAnimation:NO];
[self.findBarCoordinator stop];
}
- (void)webStateList:(WebStateList*)webStateList
......@@ -4538,7 +4556,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
} else {
// Hide UI accessories such as find bar and first visit overlays
// for welcome page.
[self.findBarCoordinator hideFindBarWithAnimation:NO];
[self.findBarCoordinator stop];
[self.infobarContainerCoordinator hideContainer:YES];
}
}
......@@ -4719,6 +4737,59 @@ NSString* const kBrowserViewControllerSnackbarCategory =
atOffset:[self currentHeaderOffset]];
}
- (void)toolbarAccessoryCoordinatorDidDismissUI:
(ChromeCoordinator*)coordinator {
if (self.nextToolbarCoordinator == self.findBarCoordinator) {
dispatch_async(dispatch_get_main_queue(), ^{
[self showFindInPage];
});
self.nextToolbarCoordinator = nil;
} else if (self.nextToolbarCoordinator == self.textZoomCoordinator) {
dispatch_async(dispatch_get_main_queue(), ^{
[self showTextZoom];
});
self.nextToolbarCoordinator = nil;
}
}
#pragma mark - Toolbar Accessory Methods
- (ToolbarAccessoryPresenter*)toolbarAccessoryPresenter {
if (_toolbarAccessoryPresenter) {
return _toolbarAccessoryPresenter;
}
_toolbarAccessoryPresenter =
[[ToolbarAccessoryPresenter alloc] initWithIsIncognito:_isOffTheRecord];
_toolbarAccessoryPresenter.baseViewController = self;
return _toolbarAccessoryPresenter;
}
- (FindBarCoordinator*)findBarCoordinator {
if (_findBarCoordinator) {
return _findBarCoordinator;
}
_findBarCoordinator =
[[FindBarCoordinator alloc] initWithBaseViewController:self
browser:self.browser];
_findBarCoordinator.presenter = self.toolbarAccessoryPresenter;
_findBarCoordinator.delegate = self;
return _findBarCoordinator;
}
- (TextZoomCoordinator*)textZoomCoordinator {
if (_textZoomCoordinator) {
return _textZoomCoordinator;
}
_textZoomCoordinator =
[[TextZoomCoordinator alloc] initWithBaseViewController:self
browser:self.browser];
_textZoomCoordinator.presenter = self.toolbarAccessoryPresenter;
_textZoomCoordinator.delegate = self;
return _textZoomCoordinator;
}
#pragma mark - ManageAccountsDelegate
- (void)onManageAccounts {
......
......@@ -116,6 +116,12 @@ class GURL;
// prevent interaction with the web page.
- (void)showActivityOverlay:(BOOL)show;
// Shows the Text Zoom UI.
- (void)showTextZoom;
// Dismisses the Text Zoom UI.
- (void)hideTextZoom;
@end
#endif // IOS_CHROME_BROWSER_UI_COMMANDS_BROWSER_COMMANDS_H_
......@@ -13,8 +13,8 @@
@interface FindBarControllerIOS : NSObject
// The dispatcher for sending browser commands.
@property(nonatomic, weak) id<BrowserCommands> dispatcher;
// The command handler for browser commands.
@property(nonatomic, weak) id<BrowserCommands> commandHandler;
// The view controller containing all the buttons and textfields that is common
// between iPhone and iPad.
@property(nonatomic, strong, readonly)
......
......@@ -89,7 +89,7 @@ const NSTimeInterval kSearchShortDelay = 0.100;
action:@selector(editingChanged)
forControlEvents:UIControlEventEditingChanged];
[_findBarViewController.findBarView.nextButton
addTarget:self.dispatcher
addTarget:self.commandHandler
action:@selector(findNextStringInPage)
forControlEvents:UIControlEventTouchUpInside];
[_findBarViewController.findBarView.nextButton
......@@ -97,7 +97,7 @@ const NSTimeInterval kSearchShortDelay = 0.100;
action:@selector(hideKeyboard:)
forControlEvents:UIControlEventTouchUpInside];
[_findBarViewController.findBarView.previousButton
addTarget:self.dispatcher
addTarget:self.commandHandler
action:@selector(findPreviousStringInPage)
forControlEvents:UIControlEventTouchUpInside];
[_findBarViewController.findBarView.previousButton
......@@ -105,7 +105,7 @@ const NSTimeInterval kSearchShortDelay = 0.100;
action:@selector(hideKeyboard:)
forControlEvents:UIControlEventTouchUpInside];
[_findBarViewController.findBarView.closeButton
addTarget:self.dispatcher
addTarget:self.commandHandler
action:@selector(closeFindInPage)
forControlEvents:UIControlEventTouchUpInside];
......@@ -203,7 +203,7 @@ const NSTimeInterval kSearchShortDelay = 0.100;
[self.delayTimer invalidate];
NSUInteger length = [[self searchTerm] length];
if (length == 0) {
[self.dispatcher searchFindInPage];
[self.commandHandler searchFindInPage];
return;
}
......@@ -214,7 +214,7 @@ const NSTimeInterval kSearchShortDelay = 0.100;
(length > kSearchDelayChars) ? kSearchShortDelay : kSearchLongDelay;
self.delayTimer =
[NSTimer scheduledTimerWithTimeInterval:delay
target:self.dispatcher
target:self.commandHandler
selector:@selector(searchFindInPage)
userInfo:nil
repeats:NO];
......
......@@ -25,15 +25,6 @@
// make the transition easier.
@property(nonatomic, strong) FindBarControllerIOS* findBarController;
// Starts the Find In Page process.
- (void)startFindInPage;
// Shows the Find Bar UI.
- (void)showFindBarAnimated:(BOOL)animated;
// Hides the Find Bar UI.
- (void)hideFindBarWithAnimation:(BOOL)animated;
// Defocuses the Find Bar text field.
- (void)defocusFindBar;
......
......@@ -24,36 +24,48 @@
@interface FindBarCoordinator () <FindInPageResponseDelegate,
ContainedPresenterDelegate>
// Command handler for |BrowserCommand|s.
@property(nonatomic, readonly) id<BrowserCommands> browserCommandHandler;
@end
@implementation FindBarCoordinator
- (void)start {
self.findBarController = [[FindBarControllerIOS alloc]
initWithIncognito:self.browserState->IsOffTheRecord()];
if (!self.findBarController) {
self.findBarController = [[FindBarControllerIOS alloc]
initWithIncognito:self.browserState->IsOffTheRecord()];
self.findBarController.commandHandler = self.browserCommandHandler;
}
self.presenter.delegate = self;
self.findBarController.dispatcher =
static_cast<id<BrowserCommands>>(self.browser->GetCommandDispatcher());
}
- (void)startFindInPage {
DCHECK(self.currentWebState);
FindTabHelper* helper = FindTabHelper::FromWebState(self.currentWebState);
DCHECK(!helper->IsFindUIActive());
helper->SetResponseDelegate(self);
helper->SetFindUIActive(true);
[self showFindBarAnimated:YES shouldFocus:YES];
// If the FindUI is already active, just reshow it.
if (helper->IsFindUIActive()) {
[self showAnimated:NO shouldFocus:[self.findBarController isFocused]];
} else {
DCHECK(!helper->IsFindUIActive());
helper->SetResponseDelegate(self);
helper->SetFindUIActive(true);
[self showAnimated:YES shouldFocus:YES];
}
}
- (void)showFindBarAnimated:(BOOL)animated {
[self showFindBarAnimated:animated
shouldFocus:[self.findBarController isFocused]];
- (void)stop {
if (!self.presenter.isPresenting) {
return;
}
FindTabHelper* helper = FindTabHelper::FromWebState(self.currentWebState);
// If the FindUI is still active, the dismiss should be unanimated, because
// the UI will be brought back later.
BOOL animated = helper && !helper->IsFindUIActive();
[self.findBarController findBarViewWillHide];
[self.presenter dismissAnimated:animated];
}
- (void)showFindBarAnimated:(BOOL)animated shouldFocus:(BOOL)shouldFocus {
- (void)showAnimated:(BOOL)animated shouldFocus:(BOOL)shouldFocus {
self.presenter.presentedViewController =
self.findBarController.findBarViewController;
......@@ -77,11 +89,6 @@
focusTextfield:shouldFocus];
}
- (void)hideFindBarWithAnimation:(BOOL)animated {
[self.findBarController findBarViewWillHide];
[self.presenter dismissAnimated:animated];
}
- (void)defocusFindBar {
FindTabHelper* helper = FindTabHelper::FromWebState(self.currentWebState);
if (helper && helper->IsFindUIActive()) {
......@@ -98,7 +105,7 @@
}
- (void)findDidStop {
[self hideFindBarWithAnimation:YES];
[self.browserCommandHandler closeFindInPage];
}
#pragma mark - ContainedPresenterDelegate
......@@ -109,6 +116,7 @@
- (void)containedPresenterDidDismiss:(id<ContainedPresenter>)presenter {
[self.findBarController findBarViewDidHide];
[self.delegate toolbarAccessoryCoordinatorDidDismissUI:self];
}
#pragma mark - Private
......@@ -119,4 +127,9 @@
: nullptr;
}
- (id<BrowserCommands>)browserCommandHandler {
return HandlerForProtocol(self.browser->GetCommandDispatcher(),
BrowserCommands);
}
@end
......@@ -110,6 +110,7 @@ using base::UserMetricsAction;
break;
case PopupMenuActionTextZoom:
RecordAction(UserMetricsAction("MobileMenuTextZoom"));
[self.dispatcher showTextZoom];
break;
#if !defined(NDEBUG)
case PopupMenuActionViewSource:
......
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
source_set("text_zoom") {
sources = [
"text_zoom_coordinator.h",
"text_zoom_coordinator.mm",
]
deps = [
":text_zoom_ui",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/main",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/browser/ui/presenters",
"//ios/chrome/browser/ui/toolbar/accessory",
"//ios/chrome/browser/ui/toolbar/public:constants",
"//ios/chrome/common/colors",
]
configs += [ "//build/config/compiler:enable_arc" ]
}
source_set("text_zoom_ui") {
sources = [
"text_zoom_view_controller.h",
"text_zoom_view_controller.mm",
]
deps = [
"//components/strings:components_strings",
"//ios/chrome/browser/ui/commands",
"//ui/base",
]
configs += [ "//build/config/compiler:enable_arc" ]
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_TEXT_ZOOM_TEXT_ZOOM_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_TEXT_ZOOM_TEXT_ZOOM_COORDINATOR_H_
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h"
@class TextZoomViewController;
@class ToolbarAccessoryPresenter;
@protocol ToolbarAccessoryCoordinatorDelegate;
// Coordinator for the UI of the text zoom feature, which allows adjusting the
// zoom level of the text of a webpage.
@interface TextZoomCoordinator : ChromeCoordinator
// Presenter used by this coordinator to present itself.
@property(nonatomic, strong) ToolbarAccessoryPresenter* presenter;
// Delegate to inform when this coordinator's UI is dismissed.
@property(nonatomic, weak) id<ToolbarAccessoryCoordinatorDelegate> delegate;
@end
#endif // IOS_CHROME_BROWSER_UI_TEXT_ZOOM_TEXT_ZOOM_COORDINATOR_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/text_zoom/text_zoom_coordinator.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#include "ios/chrome/browser/ui/presenters/contained_presenter_delegate.h"
#import "ios/chrome/browser/ui/text_zoom/text_zoom_view_controller.h"
#import "ios/chrome/browser/ui/toolbar/accessory/toolbar_accessory_coordinator_delegate.h"
#import "ios/chrome/browser/ui/toolbar/accessory/toolbar_accessory_presenter.h"
#import "ios/chrome/browser/ui/toolbar/public/toolbar_constants.h"
#import "ios/chrome/common/colors/dynamic_color_util.h"
#import "ios/chrome/common/colors/semantic_color_names.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface TextZoomCoordinator () <ContainedPresenterDelegate>
// The view controller managed by this coordinator.
@property(nonatomic, strong, readwrite)
TextZoomViewController* textZoomViewController;
@end
@implementation TextZoomCoordinator
#pragma mark - ChromeCoordinator
- (void)start {
self.textZoomViewController = [[TextZoomViewController alloc] init];
self.textZoomViewController.commandHandler =
HandlerForProtocol(self.browser->GetCommandDispatcher(), BrowserCommands);
[self showAnimated:YES];
}
- (void)stop {
[self.presenter dismissAnimated:YES];
self.textZoomViewController = nil;
}
- (void)showAnimated:(BOOL)animated {
self.presenter.presentedViewController = self.textZoomViewController;
self.presenter.delegate = self;
[self.presenter prepareForPresentation];
[self.presenter presentAnimated:animated];
}
#pragma mark - ContainedPresenterDelegate
- (void)containedPresenterDidDismiss:(id<ContainedPresenter>)presenter {
[self.delegate toolbarAccessoryCoordinatorDidDismissUI:self];
}
@end
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_TEXT_ZOOM_TEXT_ZOOM_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_TEXT_ZOOM_TEXT_ZOOM_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
@protocol BrowserCommands;
@interface TextZoomViewController : UIViewController
@property(nonatomic, weak) id<BrowserCommands> commandHandler;
@end
#endif // IOS_CHROME_BROWSER_UI_TEXT_ZOOM_TEXT_ZOOM_VIEW_CONTROLLER_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/text_zoom/text_zoom_view_controller.h"
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Horizontal padding between all elements (except the previous/next buttons).
const CGFloat kPadding = 8;
const CGFloat kButtonFontSize = 17;
}
@interface TextZoomViewController ()
@property(nonatomic, strong) UIButton* closeButton;
@end
@implementation TextZoomViewController
#pragma mark - UIViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:self.closeButton];
[NSLayoutConstraint activateConstraints:@[
// Close Button.
[self.closeButton.centerYAnchor
constraintEqualToAnchor:self.view.centerYAnchor],
// [self.closeButton.heightAnchor constraintEqualToConstant:kButtonLength],
// Use button intrinsic width.
[self.closeButton.trailingAnchor
constraintEqualToAnchor:self.view.safeAreaLayoutGuide.trailingAnchor
constant:-kPadding],
]];
[self.closeButton
setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh + 1
forAxis:UILayoutConstraintAxisHorizontal];
}
#pragma mark - Private methods (control actions)
- (void)closeButtonWasTapped:(id)sender {
[self.commandHandler hideTextZoom];
}
#pragma mark - Private property Accessors
// Creates and returns the close button.
- (UIButton*)closeButton {
if (!_closeButton) {
_closeButton = [UIButton buttonWithType:UIButtonTypeSystem];
[_closeButton setTitle:l10n_util::GetNSString(IDS_DONE)
forState:UIControlStateNormal];
_closeButton.translatesAutoresizingMaskIntoConstraints = NO;
// _closeButton.accessibilityIdentifier = kFindInPageCloseButtonId;
_closeButton.titleLabel.font = [UIFont systemFontOfSize:kButtonFontSize];
[_closeButton addTarget:self
action:@selector(closeButtonWasTapped:)
forControlEvents:UIControlEventTouchUpInside];
}
return _closeButton;
}
@end
......@@ -12,6 +12,9 @@
- (void)setHeadersForToolbarAccessoryCoordinator:
(ChromeCoordinator*)toolbarAccessoryCoordinator;
- (void)toolbarAccessoryCoordinatorDidDismissUI:
(ChromeCoordinator*)toolbarAccessoryCoordinator;
@end
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_ACCESSORY_TOOLBAR_ACCESSORY_COORDINATOR_DELEGATE_H_
......@@ -18,6 +18,9 @@
- (instancetype)init NS_UNAVAILABLE;
// Whether the presenter is currently presenting a view
@property(nonatomic, readonly, getter=isPresenting) BOOL presenting;
// The main presented view.
@property(nonatomic, strong, readonly) UIView* backgroundView;
......
......@@ -36,6 +36,9 @@ const CGFloat kAnimationDuration = 0.15;
@interface ToolbarAccessoryPresenter ()
// The |presenting| public property redefined as readwrite.
@property(nonatomic, assign, readwrite, getter=isPresenting) BOOL presenting;
// The view that acts as the background for |presentedView|, redefined as
// readwrite. This is especially important on iPhone, as this view that holds
// everything around the safe area.
......@@ -66,6 +69,7 @@ const CGFloat kAnimationDuration = 0.15;
}
- (void)prepareForPresentation {
self.presenting = YES;
self.backgroundView = [self createBackgroundView];
[self.baseViewController addChildViewController:self.presentedViewController];
[self.baseViewController.view addSubview:self.backgroundView];
......@@ -75,32 +79,39 @@ const CGFloat kAnimationDuration = 0.15;
} else {
[self prepareForPresentationOnIPad];
}
// Force initial layout before the animation.
[self.baseViewController.view layoutIfNeeded];
}
- (void)presentAnimated:(BOOL)animated {
if (animated) {
// Force initial layout before the animation.
[self.baseViewController.view layoutIfNeeded];
}
if (ShouldShowCompactToolbar()) {
[self setupFinalConstraintsOnIPhone];
} else {
[self setupFinalConstraintsOnIPad];
}
CGFloat duration = animated ? kAnimationDuration : 0;
__weak __typeof(self) weakSelf = self;
[UIView animateWithDuration:duration
animations:^() {
[self.backgroundView layoutIfNeeded];
}
completion:^(BOOL finished) {
[weakSelf.presentedViewController
didMoveToParentViewController:weakSelf.baseViewController];
if ([weakSelf.delegate
respondsToSelector:@selector(containedPresenterDidPresent:)]) {
[weakSelf.delegate containedPresenterDidPresent:weakSelf];
}
}];
auto completion = ^void(BOOL) {
[weakSelf.presentedViewController
didMoveToParentViewController:weakSelf.baseViewController];
if ([weakSelf.delegate
respondsToSelector:@selector(containedPresenterDidPresent:)]) {
[weakSelf.delegate containedPresenterDidPresent:weakSelf];
}
};
if (animated) {
[UIView animateWithDuration:kAnimationDuration
animations:^() {
[self.baseViewController.view layoutIfNeeded];
}
completion:completion];
} else {
completion(YES);
}
}
- (void)dismissAnimated:(BOOL)animated {
......@@ -116,6 +127,8 @@ const CGFloat kAnimationDuration = 0.15;
[weakSelf.delegate containedPresenterDidDismiss:weakSelf];
}
weakSelf.backgroundView = nil;
weakSelf.presenting = NO;
[weakSelf.delegate containedPresenterDidDismiss:weakSelf];
};
if (animated) {
void (^animation)();
......
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