Commit b7b14383 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Add Overscroll Actions support to SadTabViewController.

This CL adds OverscrollActionsController to SadTabViewController.
OverscrollActionsController requires UIScrollView to work, so
SadTabViewController creates a dummy scroll view to hold SadTabView.

Bug: 901563
Change-Id: I564ed10b807d774b891d86c21cda58435a5681c2
Reviewed-on: https://chromium-review.googlesource.com/c/1332390Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Commit-Queue: Eugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607780}
parent 89bc625d
......@@ -2413,6 +2413,7 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
browserState:_browserState];
sadTabCoordinator.dispatcher = self.dispatcher;
sadTabCoordinator.delegate = self;
sadTabCoordinator.overscrollDelegate = self;
_sadTabCoordinator = sadTabCoordinator;
} else {
SadTabLegacyCoordinator* sadTabCoordinator =
......
......@@ -20,6 +20,7 @@ source_set("sad_tab") {
"//ios/chrome/browser/ui",
"//ios/chrome/browser/ui/colors",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/overscroll_actions",
"//ios/chrome/browser/ui/util",
"//ios/third_party/material_components_ios",
"//ios/third_party/material_roboto_font_loader_ios",
......@@ -54,6 +55,7 @@ source_set("coordinator") {
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/browser/ui/overscroll_actions",
"//ios/chrome/browser/ui/util",
"//ios/chrome/browser/web",
"//ios/chrome/browser/web:tab_helper_delegates",
......
......@@ -10,6 +10,7 @@
@protocol ApplicationCommands;
@protocol BrowserCommands;
@protocol OverscrollActionsControllerDelegate;
@class SadTabCoordinator;
@protocol SadTabCoordinatorDelegate
......@@ -24,6 +25,11 @@
@property(nonatomic, weak) id<SadTabCoordinatorDelegate> delegate;
// Required to support Overscroll Actions UI, which is displayed when Sad Tab is
// pulled down.
@property(nonatomic, weak) id<OverscrollActionsControllerDelegate>
overscrollDelegate;
@property(nonatomic, readonly) UIViewController* viewController;
// YES if page load for this URL has failed more than once.
......
......@@ -8,6 +8,7 @@
#import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.h"
#import "ios/chrome/browser/ui/sad_tab/sad_tab_view_controller.h"
#import "ios/chrome/browser/web/sad_tab_tab_helper.h"
#import "ios/chrome/common/ui_util/constraints_ui_util.h"
......@@ -25,6 +26,7 @@
@implementation SadTabCoordinator
@synthesize dispatcher = _dispatcher;
@synthesize delegate = _delegate;
@synthesize overscrollDelegate = _overscrollDelegate;
@synthesize viewController = _viewController;
@synthesize repeatedFailure = _repeatedFailure;
......@@ -34,6 +36,7 @@
_viewController = [[SadTabViewController alloc] init];
_viewController.delegate = self;
_viewController.overscrollDelegate = self.overscrollDelegate;
_viewController.offTheRecord = self.browserState->IsOffTheRecord();
_viewController.repeatedFailure = _repeatedFailure;
......@@ -54,6 +57,12 @@
_viewController = nil;
}
- (void)setOverscrollDelegate:
(id<OverscrollActionsControllerDelegate>)delegate {
_viewController.overscrollDelegate = delegate;
_overscrollDelegate = delegate;
}
#pragma mark - SadTabViewDelegate
- (void)sadTabViewControllerShowReportAnIssue:
......
......@@ -8,6 +8,7 @@
#import <UIKit/UIKit.h>
class GURL;
@protocol OverscrollActionsControllerDelegate;
@class SadTabViewController;
@protocol SadTabViewControllerDelegate<NSObject>
......@@ -28,6 +29,11 @@ class GURL;
@property(nonatomic, weak) id<SadTabViewControllerDelegate> delegate;
// Required to support Overscroll Actions UI, which is displayed when Sad Tab is
// pulled down.
@property(nonatomic, weak) id<OverscrollActionsControllerDelegate>
overscrollDelegate;
// YES if page load for this URL has failed more than once.
@property(nonatomic, assign) BOOL repeatedFailure;
......
......@@ -4,7 +4,11 @@
#import "ios/chrome/browser/ui/sad_tab/sad_tab_view_controller.h"
#include <CoreGraphics/CoreGraphics.h>
#import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.h"
#import "ios/chrome/browser/ui/sad_tab/sad_tab_view.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#import "ios/chrome/common/ui_util/constraints_ui_util.h"
#include "url/gurl.h"
......@@ -16,6 +20,14 @@
@property(nonatomic) SadTabView* sadTabView;
// Scroll view is required by OverscrollActionsController and will be a parent
// view of the sad tab view.
@property(nonatomic) UIScrollView* scrollView;
// Allows supporting Overscroll Actions UI, which is displayed when Sad Tab is
// pulled down.
@property(nonatomic) OverscrollActionsController* overscrollActionsController;
@end
@implementation SadTabViewController
......@@ -23,21 +35,58 @@
@synthesize repeatedFailure = _repeatedFailure;
@synthesize offTheRecord = _offTheRecord;
@synthesize sadTabView = _sadTabView;
@synthesize scrollView = _scrollView;
@synthesize overscrollActionsController = _overscrollActionsController;
@synthesize overscrollDelegate = _overscrollDelegate;
#pragma mark - UIViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Scroll view is required by OverscrollActionsController and will be a parent
// view of the sad tab view.
self.scrollView = [[UIScrollView alloc] init];
self.scrollView.showsVerticalScrollIndicator = NO;
[self.view addSubview:self.scrollView];
self.scrollView.translatesAutoresizingMaskIntoConstraints = NO;
AddSameConstraints(self.scrollView, self.view);
// SadTabView is a child of the scroll view as reqired by
// OverscrollActionsController.
SadTabViewMode mode =
self.repeatedFailure ? SadTabViewMode::FEEDBACK : SadTabViewMode::RELOAD;
self.sadTabView =
[[SadTabView alloc] initWithMode:mode offTheRecord:self.offTheRecord];
self.sadTabView.translatesAutoresizingMaskIntoConstraints = NO;
self.sadTabView.delegate = self;
[self.view addSubview:self.sadTabView];
[self.scrollView addSubview:self.sadTabView];
// OverscrollActionsController allows Overscroll Actions UI.
self.overscrollActionsController =
[[OverscrollActionsController alloc] initWithScrollView:self.scrollView];
self.overscrollActionsController.delegate = self.overscrollDelegate;
self.scrollView.delegate = self.overscrollActionsController;
OverscrollStyle style = self.offTheRecord
? OverscrollStyle::REGULAR_PAGE_INCOGNITO
: OverscrollStyle::REGULAR_PAGE_NON_INCOGNITO;
[self.overscrollActionsController setStyle:style];
[self updateOverscrollActionsState];
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
AddSameConstraints(self.sadTabView, self.view);
// In order to allow UIScollView to scroll vertically, the height of the
// content should be taller than the hight of the scroll view.
CGRect newFrame = self.view.bounds;
newFrame.size.height += 1;
self.sadTabView.frame = newFrame;
[self.scrollView setContentSize:newFrame.size];
}
- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
[self updateOverscrollActionsState];
}
#pragma mark - SadTabViewDelegate
......@@ -55,6 +104,17 @@
[self.delegate sadTabViewControllerReload:self];
}
#pragma mark - Private
// Enables or disables overscroll actions.
- (void)updateOverscrollActionsState {
if (IsSplitToolbarMode(self)) {
[self.overscrollActionsController enableOverscrollActions];
} else {
[self.overscrollActionsController disableOverscrollActions];
}
}
@end
#pragma mark -
......
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