Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Unified Diff: ios/chrome/browser/ui/alert_coordinator/alert_coordinator.mm

Issue 2167683002: Creates coordinator for ActionSheet and TextInput (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@alertCoordinator
Patch Set: Keep message property Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/alert_coordinator/alert_coordinator.mm
diff --git a/ios/chrome/browser/ui/alert_coordinator/alert_coordinator.mm b/ios/chrome/browser/ui/alert_coordinator/alert_coordinator.mm
index a57e2b50c95c1e4a6eee9c0d00f7a743a49472b5..ef5f1ccd03b9024587f55fdf31e940b5ab9b952f 100644
--- a/ios/chrome/browser/ui/alert_coordinator/alert_coordinator.mm
+++ b/ios/chrome/browser/ui/alert_coordinator/alert_coordinator.mm
@@ -12,26 +12,21 @@
@interface AlertCoordinator () {
// Variables backing properties of the same name.
base::scoped_nsobject<UIAlertController> _alertController;
- base::scoped_nsobject<NSString> _message;
// Title for the alert.
base::scoped_nsobject<NSString> _title;
- // Rectangle for the popover alert.
- CGRect _rect;
- // View for the popovert alert.
- base::scoped_nsobject<UIView> _view;
- // Style for this alert.
- UIAlertControllerStyle _style;
+ // Message for the alert.
+ base::scoped_nsobject<NSString> _message;
}
// Redefined to readwrite.
@property(nonatomic, readwrite, getter=isVisible) BOOL visible;
-// Lazy initializer to create the |_alert|.
-@property(nonatomic, readonly) UIAlertController* alertController;
// Called when the alert is dismissed to perform cleanup.
- (void)alertDismissed;
+- (UIAlertController*)alertControllerWithTitle:(NSString*)title
+ message:(NSString*)message;
@end
@implementation AlertCoordinator
@@ -45,26 +40,18 @@
}
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
- title:(NSString*)title {
+ title:(NSString*)title
+ message:(NSString*)message {
self = [super initWithBaseViewController:viewController];
if (self) {
- _style = UIAlertControllerStyleAlert;
_title.reset([title copy]);
+ _message.reset([message copy]);
}
return self;
}
#pragma mark - Public Methods.
-- (void)configureForActionSheetWithRect:(CGRect)rect popoverView:(UIView*)view {
- if (_alertController)
- return;
-
- _style = UIAlertControllerStyleActionSheet;
- _view.reset(view);
- _rect = rect;
-}
-
- (void)addItemWithTitle:(NSString*)title
action:(ProceduralBlock)actionBlock
style:(UIAlertActionStyle)style {
@@ -82,9 +69,9 @@
[UIAlertAction actionWithTitle:title
style:style
handler:^(UIAlertAction*) {
- [weakSelf alertDismissed];
if (actionBlock)
actionBlock();
+ [weakSelf alertDismissed];
}];
[self.alertController addAction:alertAction];
@@ -99,7 +86,7 @@
}
// Display at least one button to let the user dismiss the alert.
- if ([self actionsCount] == 0) {
+ if ([self.alertController actions].count == 0) {
[self addItemWithTitle:l10n_util::GetNSString(IDS_APP_OK)
action:nil
style:UIAlertActionStyleDefault];
@@ -116,26 +103,15 @@
[self alertDismissed];
}
-- (NSUInteger)actionsCount {
- return [_alertController actions].count;
-}
-
#pragma mark - Property Implementation.
- (UIAlertController*)alertController {
if (!_alertController) {
UIAlertController* alert =
- [UIAlertController alertControllerWithTitle:_title
- message:_message
- preferredStyle:_style];
+ [self alertControllerWithTitle:_title message:_message];
if (alert)
_alertController.reset([alert retain]);
-
- if (_style == UIAlertControllerStyleActionSheet) {
- alert.popoverPresentationController.sourceView = _view;
- alert.popoverPresentationController.sourceRect = _rect;
- }
}
return _alertController;
}
@@ -156,4 +132,12 @@
_alertController.reset();
}
+- (UIAlertController*)alertControllerWithTitle:(NSString*)title
+ message:(NSString*)message {
+ return
+ [UIAlertController alertControllerWithTitle:title
+ message:message
+ preferredStyle:UIAlertControllerStyleAlert];
+}
+
@end

Powered by Google App Engine
This is Rietveld 408576698