forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ios] Creates a base class for Settings table views.
Integrating with the MDC AppBar requires a bunch of boilerplate setup and scrollview delegate code. Move that code to a separate base class, so that the tableview cell catalog class becomes simpler and easier to read. BUG=811075 Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs Change-Id: I8a14d2f8aacc60480c50ee1a361c3413b82dd20a Reviewed-on: https://chromium-review.googlesource.com/913669 Reviewed-by: Sergio Collazos <sczs@chromium.org> Commit-Queue: Rohit Rao <rohitrao@chromium.org> Cr-Commit-Position: refs/heads/master@{#536109}
- Loading branch information
Showing
5 changed files
with
163 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
ios/chrome/browser/ui/settings/settings_root_table_view_controller.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2018 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_SETTINGS_SETTINGS_ROOT_TABLE_VIEW_CONTROLLER_H_ | ||
#define IOS_CHROME_BROWSER_UI_SETTINGS_SETTINGS_ROOT_TABLE_VIEW_CONTROLLER_H_ | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
#import "ios/chrome/browser/ui/material_components/app_bar_presenting.h" | ||
|
||
// SettingsRootTableViewController is a base class for integrating UITableViews | ||
// into the Settings UI. It handles the configuration and display of the MDC | ||
// AppBar. | ||
@interface SettingsRootTableViewController | ||
: UITableViewController<AppBarPresenting> | ||
|
||
- (instancetype)initWithStyle:(UITableViewStyle)style NS_DESIGNATED_INITIALIZER; | ||
- (instancetype)initWithNibName:(NSString*)name | ||
bundle:(NSBundle*)bundle NS_UNAVAILABLE; | ||
- (instancetype)initWithCoder:(NSCoder*)decoder NS_UNAVAILABLE; | ||
|
||
#pragma mark UIScrollViewDelegate | ||
|
||
// Updates the MDCFlexibleHeader with changes to the table view scroll | ||
// state. Must be called by subclasses if they override this method in order to | ||
// maintain this functionality. | ||
- (void)scrollViewDidScroll:(UIScrollView*)scrollView NS_REQUIRES_SUPER; | ||
|
||
// Updates the MDCFlexibleHeader with changes to the table view scroll | ||
// state. Must be called by subclasses if they override this method in order to | ||
// maintain this functionality. | ||
- (void)scrollViewDidEndDragging:(UIScrollView*)scrollView | ||
willDecelerate:(BOOL)decelerate NS_REQUIRES_SUPER; | ||
|
||
// Updates the MDCFlexibleHeader with changes to the table view scroll | ||
// state. Must be called by subclasses if they override this method in order to | ||
// maintain this functionality. | ||
- (void)scrollViewDidEndDecelerating:(UIScrollView*)scrollView | ||
NS_REQUIRES_SUPER; | ||
|
||
// Updates the MDCFlexibleHeader with changes to the table view scroll | ||
// state. Must be called by subclasses if they override this method in order to | ||
// maintain this functionality. | ||
- (void)scrollViewWillEndDragging:(UIScrollView*)scrollView | ||
withVelocity:(CGPoint)velocity | ||
targetContentOffset:(inout CGPoint*)targetContentOffset | ||
NS_REQUIRES_SUPER; | ||
|
||
@end | ||
|
||
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_SETTINGS_ROOT_TABLE_VIEW_CONTROLLER_H_ |
106 changes: 106 additions & 0 deletions
106
ios/chrome/browser/ui/settings/settings_root_table_view_controller.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright 2018 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/settings/settings_root_table_view_controller.h" | ||
|
||
#import "base/mac/foundation_util.h" | ||
#import "ios/chrome/browser/ui/material_components/utils.h" | ||
#import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" | ||
#import "ios/third_party/material_components_ios/src/components/AppBar/src/MaterialAppBar.h" | ||
|
||
#if !defined(__has_feature) || !__has_feature(objc_arc) | ||
#error "This file requires ARC support." | ||
#endif | ||
|
||
@interface SettingsRootTableViewController () | ||
|
||
// The AppBar for this view controller. | ||
@property(nonatomic, readwrite, strong) MDCAppBar* appBar; | ||
|
||
@end | ||
|
||
@implementation SettingsRootTableViewController | ||
@synthesize appBar = _appBar; | ||
|
||
- (instancetype)initWithStyle:(UITableViewStyle)style { | ||
if ((self = [super initWithStyle:style])) { | ||
// Configure the AppBar. | ||
_appBar = [[MDCAppBar alloc] init]; | ||
[self addChildViewController:_appBar.headerViewController]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
|
||
// Configure the app bar. This cannot be in a shared base class because | ||
// UITableViewControllers normally do not use MDC styling, but this one does | ||
// in order to match the other Settings screens. | ||
ConfigureAppBarWithCardStyle(self.appBar); | ||
self.appBar.headerViewController.headerView.trackingScrollView = | ||
self.tableView; | ||
// Add the AppBar's views after all other views have been registered. | ||
[self.appBar addSubviewsToParent]; | ||
} | ||
|
||
- (void)viewWillAppear:(BOOL)animated { | ||
[super viewWillAppear:animated]; | ||
|
||
// Set up the "Done" button in the upper right of the nav bar. | ||
SettingsNavigationController* navigationController = | ||
base::mac::ObjCCast<SettingsNavigationController>( | ||
self.navigationController); | ||
UIBarButtonItem* doneButton = [navigationController doneButton]; | ||
self.navigationItem.rightBarButtonItem = doneButton; | ||
} | ||
|
||
- (UIViewController*)childViewControllerForStatusBarHidden { | ||
return self.appBar.headerViewController; | ||
} | ||
|
||
- (UIViewController*)childViewControllerForStatusBarStyle { | ||
return self.appBar.headerViewController; | ||
} | ||
|
||
#pragma mark UIScrollViewDelegate | ||
|
||
- (void)scrollViewDidScroll:(UIScrollView*)scrollView { | ||
MDCFlexibleHeaderView* headerView = | ||
self.appBar.headerViewController.headerView; | ||
if (scrollView == headerView.trackingScrollView) { | ||
[headerView trackingScrollViewDidScroll]; | ||
} | ||
} | ||
|
||
- (void)scrollViewDidEndDecelerating:(UIScrollView*)scrollView { | ||
MDCFlexibleHeaderView* headerView = | ||
self.appBar.headerViewController.headerView; | ||
if (scrollView == headerView.trackingScrollView) { | ||
[headerView trackingScrollViewDidEndDecelerating]; | ||
} | ||
} | ||
|
||
- (void)scrollViewDidEndDragging:(UIScrollView*)scrollView | ||
willDecelerate:(BOOL)decelerate { | ||
MDCFlexibleHeaderView* headerView = | ||
self.appBar.headerViewController.headerView; | ||
if (scrollView == headerView.trackingScrollView) { | ||
[headerView trackingScrollViewDidEndDraggingWillDecelerate:decelerate]; | ||
} | ||
} | ||
|
||
- (void)scrollViewWillEndDragging:(UIScrollView*)scrollView | ||
withVelocity:(CGPoint)velocity | ||
targetContentOffset:(inout CGPoint*)targetContentOffset { | ||
MDCFlexibleHeaderView* headerView = | ||
self.appBar.headerViewController.headerView; | ||
if (scrollView == headerView.trackingScrollView) { | ||
[headerView | ||
trackingScrollViewWillEndDraggingWithVelocity:velocity | ||
targetContentOffset:targetContentOffset]; | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters