Commit d82f3a1a authored by sczs's avatar sczs Committed by Commit Bot

[ios] Makes SettingsRootTableVC conform to AdaptivePresentationControllerDelegate

Since Settings might embed 3rd party ViewControllers, the only interface we could
expect from them in order to clean up or rubberband when swiping down to dismiss
are the AdaptivePresentationControllerDelegate instance methods. For this reason
SettingsRootTableVC now conforms to AdaptivePresentationControllerDelegate, and
any subclass can override or implement any of the these methods.

This CL also forwards all AdaptivePresentationControllerDelegate method calls into
the currently presented Settings VC.

Bug: 1006304
Change-Id: I0ff47d755e5c3e67029e210dfb94d21d700520cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1832104Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702016}
parent e93de3a3
...@@ -303,9 +303,10 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -303,9 +303,10 @@ typedef NS_ENUM(NSInteger, ItemType) {
} }
} }
#pragma mark - SettingsRootTableViewController #pragma mark - UIAdaptivePresentationControllerDelegate
- (BOOL)shouldDismissViewControllerBySwipeDown { - (BOOL)presentationControllerShouldDismiss:
(UIPresentationController*)presentationController {
return !self.tableView.editing; return !self.tableView.editing;
} }
......
...@@ -73,7 +73,10 @@ ...@@ -73,7 +73,10 @@
return YES; return YES;
} }
- (BOOL)shouldDismissViewControllerBySwipeDown { #pragma mark - UIAdaptivePresentationControllerDelegate
- (BOOL)presentationControllerShouldDismiss:
(UIPresentationController*)presentationController {
return !self.tableView.editing; return !self.tableView.editing;
} }
......
...@@ -334,12 +334,6 @@ ...@@ -334,12 +334,6 @@
} }
} }
#pragma mark - SettingsRootTableViewController
- (BOOL)shouldDismissViewControllerBySwipeDown {
return !self.chromeActivityOverlayCoordinator.started;
}
#pragma mark - TableViewTextLinkCellDelegate #pragma mark - TableViewTextLinkCellDelegate
- (void)tableViewTextLinkCell:(TableViewTextLinkCell*)cell - (void)tableViewTextLinkCell:(TableViewTextLinkCell*)cell
...@@ -436,8 +430,8 @@ ...@@ -436,8 +430,8 @@
- (void)presentationControllerDidDismiss: - (void)presentationControllerDidDismiss:
(UIPresentationController*)presentationController { (UIPresentationController*)presentationController {
// Call dismiss to clean up state and stop the Coordinator. // Call prepareForDismissal to clean up state and stop the Coordinator.
[self dismiss]; [self prepareForDismissal];
} }
- (BOOL)presentationControllerShouldDismiss: - (BOOL)presentationControllerShouldDismiss:
......
...@@ -47,11 +47,13 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId"; ...@@ -47,11 +47,13 @@ NSString* const kSettingsDoneButtonId = @"kSettingsDoneButtonId";
@property(nonatomic, strong) @property(nonatomic, strong)
GoogleServicesSettingsCoordinator* googleServicesSettingsCoordinator; GoogleServicesSettingsCoordinator* googleServicesSettingsCoordinator;
// Current SettingsViewController being presented by this Navigation Controller. // Current UIViewController being presented by this Navigation Controller.
// If nil it means the Navigation Controller is not presenting anything, or the // If nil it means the Navigation Controller is not presenting anything, or the
// VC being presented is not a SettingsRootTableViewController. // VC being presented doesn't conform to
// UIAdaptivePresentationControllerDelegate.
@property(nonatomic, weak) @property(nonatomic, weak)
SettingsRootTableViewController* currentPresentedSettingsViewController; UIViewController<UIAdaptivePresentationControllerDelegate>*
currentPresentedViewController;
// The SettingsNavigationControllerDelegate for this NavigationController. // The SettingsNavigationControllerDelegate for this NavigationController.
@property(nonatomic, weak) id<SettingsNavigationControllerDelegate> @property(nonatomic, weak) id<SettingsNavigationControllerDelegate>
...@@ -376,16 +378,53 @@ initWithRootViewController:(UIViewController*)rootViewController ...@@ -376,16 +378,53 @@ initWithRootViewController:(UIViewController*)rootViewController
- (BOOL)presentationControllerShouldDismiss: - (BOOL)presentationControllerShouldDismiss:
(UIPresentationController*)presentationController { (UIPresentationController*)presentationController {
return [self.currentPresentedSettingsViewController if (@available(iOS 13, *)) {
shouldDismissViewControllerBySwipeDown]; if ([self.currentPresentedViewController
respondsToSelector:@selector
(presentationControllerShouldDismiss:)]) {
return [self.currentPresentedViewController
presentationControllerShouldDismiss:presentationController];
}
}
return NO;
} }
- (void)presentationControllerDidDismiss: - (void)presentationControllerDidDismiss:
(UIPresentationController*)presentationController { (UIPresentationController*)presentationController {
if (@available(iOS 13, *)) {
if ([self.currentPresentedViewController
respondsToSelector:@selector(presentationControllerDidDismiss:)]) {
[self.currentPresentedViewController
presentationControllerDidDismiss:presentationController];
}
}
// Call settingsWasDismissed to make sure any necessary cleanup is performed. // Call settingsWasDismissed to make sure any necessary cleanup is performed.
[self.settingsNavigationDelegate settingsWasDismissed]; [self.settingsNavigationDelegate settingsWasDismissed];
} }
- (void)presentationControllerDidAttemptToDismiss:
(UIPresentationController*)presentationController {
if (@available(iOS 13, *)) {
if ([self.currentPresentedViewController
respondsToSelector:@selector
(presentationControllerDidAttemptToDismiss:)]) {
[self.currentPresentedViewController
presentationControllerDidAttemptToDismiss:presentationController];
}
}
}
- (void)presentationControllerWillDismiss:
(UIPresentationController*)presentationController {
if (@available(iOS 13, *)) {
if ([self.currentPresentedViewController
respondsToSelector:@selector(presentationControllerWillDismiss:)]) {
[self.currentPresentedViewController
presentationControllerWillDismiss:presentationController];
}
}
}
#pragma mark - Accessibility #pragma mark - Accessibility
- (BOOL)accessibilityPerformEscape { - (BOOL)accessibilityPerformEscape {
...@@ -407,8 +446,9 @@ initWithRootViewController:(UIViewController*)rootViewController ...@@ -407,8 +446,9 @@ initWithRootViewController:(UIViewController*)rootViewController
- (void)navigationController:(UINavigationController*)navigationController - (void)navigationController:(UINavigationController*)navigationController
willShowViewController:(UIViewController*)viewController willShowViewController:(UIViewController*)viewController
animated:(BOOL)animated { animated:(BOOL)animated {
self.currentPresentedSettingsViewController = self.currentPresentedViewController = base::mac::ObjCCast<
base::mac::ObjCCast<SettingsRootTableViewController>(viewController); UIViewController<UIAdaptivePresentationControllerDelegate>>(
viewController);
} }
#pragma mark - UIResponder #pragma mark - UIResponder
......
...@@ -19,7 +19,8 @@ extern NSString* const kSettingsToolbarDeleteButtonId; ...@@ -19,7 +19,8 @@ extern NSString* const kSettingsToolbarDeleteButtonId;
// AppBar. // AppBar.
@interface SettingsRootTableViewController @interface SettingsRootTableViewController
: ChromeTableViewController <SettingsRootViewControlling, : ChromeTableViewController <SettingsRootViewControlling,
TableViewLinkHeaderFooterItemDelegate> TableViewLinkHeaderFooterItemDelegate,
UIAdaptivePresentationControllerDelegate>
// Delete button for the toolbar. // Delete button for the toolbar.
@property(nonatomic, strong, readonly) UIBarButtonItem* deleteButton; @property(nonatomic, strong, readonly) UIBarButtonItem* deleteButton;
...@@ -81,11 +82,6 @@ extern NSString* const kSettingsToolbarDeleteButtonId; ...@@ -81,11 +82,6 @@ extern NSString* const kSettingsToolbarDeleteButtonId;
// * Removes the transparent veil. // * Removes the transparent veil.
- (void)allowUserInteraction; - (void)allowUserInteraction;
// Returns YES. Subclasses can override to prevent a swipe down dismissal. This
// is useful when the ViewController contains editable fields and accidental
// dismissals want to be avoided.
- (BOOL)shouldDismissViewControllerBySwipeDown;
@end @end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_SETTINGS_ROOT_TABLE_VIEW_CONTROLLER_H_ #endif // IOS_CHROME_BROWSER_UI_SETTINGS_SETTINGS_ROOT_TABLE_VIEW_CONTROLLER_H_
...@@ -353,7 +353,10 @@ NSString* const kSettingsToolbarDeleteButtonId = ...@@ -353,7 +353,10 @@ NSString* const kSettingsToolbarDeleteButtonId =
self.savedBarButtonItemPosition = kUndefinedBarButtonItemPosition; self.savedBarButtonItemPosition = kUndefinedBarButtonItemPosition;
} }
- (BOOL)shouldDismissViewControllerBySwipeDown { #pragma mark - UIAdaptivePresentationControllerDelegate
- (BOOL)presentationControllerShouldDismiss:
(UIPresentationController*)presentationController {
return YES; return YES;
} }
......
...@@ -189,7 +189,10 @@ const CGFloat kSpinnerButtonPadding = 18; ...@@ -189,7 +189,10 @@ const CGFloat kSpinnerButtonPadding = 18;
forSectionWithIdentifier:SectionIdentifierPassphrase]; forSectionWithIdentifier:SectionIdentifierPassphrase];
} }
- (BOOL)shouldDismissViewControllerBySwipeDown { #pragma mark - UIAdaptivePresentationControllerDelegate
- (BOOL)presentationControllerShouldDismiss:
(UIPresentationController*)presentationController {
return ![passphrase_.text length]; return ![passphrase_.text length];
} }
......
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