Commit 791446a1 authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

[iOS][Alert] Create files for AlertAction

Tests to follow in another CL.

Bug: 951300
Change-Id: I1e622285758b22c84986242bd39e5f4c99b0496c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1590135
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#658496}
parent 8015227b
......@@ -4,6 +4,8 @@
source_set("alert_view_controller") {
sources = [
"alert_action.h",
"alert_action.mm",
"alert_consumer.h",
"alert_view_controller.h",
"alert_view_controller.mm",
......
// 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_ALERT_VIEW_CONTROLLER_ALERT_ACTION_H_
#define IOS_CHROME_BROWSER_UI_ALERT_VIEW_CONTROLLER_ALERT_ACTION_H_
#import <UIKit/UIKit.h>
// This class is a replacement for UIAlertAction. UIAlertAction doesn't expose
// its handler, rendering it unreusable.
@interface AlertAction : NSObject
// The title for this action.
@property(nonatomic, readonly) NSString* title;
// The style for this action. Matches UIAlertAction style.
@property(nonatomic, readonly) UIAlertActionStyle style;
// The unique identifier for the actions created.
@property(nonatomic, readonly) NSInteger uniqueIdentifier;
// Block to be called when this action is triggered.
@property(nonatomic, readonly) void (^handler)(AlertAction* action);
// Initializes an action with |title| and |handler|.
+ (instancetype)actionWithTitle:(NSString*)title
style:(UIAlertActionStyle)style
handler:(void (^)(AlertAction* action))handler;
- (instancetype)init NS_UNAVAILABLE;
@end
#endif // IOS_CHROME_BROWSER_UI_ALERT_VIEW_CONTROLLER_ALERT_ACTION_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/alert_view_controller/alert_action.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation AlertAction
- (instancetype)initWithTitle:(NSString*)title
style:(UIAlertActionStyle)style
handler:(void (^)(AlertAction* action))handler {
self = [super init];
if (self) {
static NSInteger actionIdentifier = 0;
_uniqueIdentifier = ++actionIdentifier;
_title = [title copy];
_handler = handler;
_style = style;
}
return self;
}
+ (instancetype)actionWithTitle:(NSString*)title
style:(UIAlertActionStyle)style
handler:(void (^)(AlertAction* action))handler {
return [[AlertAction alloc] initWithTitle:title style:style handler:handler];
}
@end
......@@ -9,26 +9,6 @@
#import "ios/chrome/browser/ui/alert_view_controller/alert_consumer.h"
// This class is a replacement for UIAlertAction.
// Current limitations:
// Actions Styles are not supported.
@interface AlertAction : NSObject
// The title for this action.
@property(nonatomic, readonly) NSString* title;
// The style for this action. Matches UIAlertAction style.
@property(nonatomic, readonly) UIAlertActionStyle style;
// Initializes an action with |title| and |handler|.
+ (instancetype)actionWithTitle:(NSString*)title
style:(UIAlertActionStyle)style
handler:(void (^)(AlertAction* action))handler;
- (instancetype)init NS_UNAVAILABLE;
@end
// This class is a replacement for UIAlertController that supports custom
// presentation styles, i.e. change modalPresentationStyle,
// modalTransitionStyle, or transitioningDelegate. The style is more similar to
......
......@@ -5,6 +5,7 @@
#import "ios/chrome/browser/ui/alert_view_controller/alert_view_controller.h"
#include "base/logging.h"
#import "ios/chrome/browser/ui/alert_view_controller/alert_action.h"
#import "ios/chrome/browser/ui/elements/gray_highlight_button.h"
#import "ios/chrome/browser/ui/elements/text_field_configuration.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
......@@ -65,43 +66,6 @@ constexpr int kTextfieldBackgroundColor = 0xf7f7f7;
} // namespace
@interface AlertAction ()
@property(nonatomic, readwrite) NSString* title;
@property(nonatomic, readwrite) UIAlertActionStyle style;
// The unique identifier for the actions created.
@property(nonatomic) NSInteger uniqueIdentifier;
// Block to be called when this action is triggered.
@property(nonatomic, copy) void (^handler)(AlertAction* action);
@end
@implementation AlertAction
- (instancetype)initWithTitle:(NSString*)title
style:(UIAlertActionStyle)style
handler:(void (^)(AlertAction* action))handler {
self = [super init];
if (self) {
static NSInteger actionIdentifier = 0;
_uniqueIdentifier = ++actionIdentifier;
_title = title;
_handler = handler;
_style = style;
}
return self;
}
+ (instancetype)actionWithTitle:(NSString*)title
style:(UIAlertActionStyle)style
handler:(void (^)(AlertAction* action))handler {
return [[AlertAction alloc] initWithTitle:title style:style handler:handler];
}
@end
@interface AlertViewController ()
// The actions for to this alert. |copy| for safety against mutable objects.
......
......@@ -4,6 +4,7 @@
#import "ios/showcase/alert/sc_alert_coordinator.h"
#import "ios/chrome/browser/ui/alert_view_controller/alert_action.h"
#import "ios/chrome/browser/ui/alert_view_controller/alert_view_controller.h"
#import "ios/chrome/browser/ui/elements/text_field_configuration.h"
......
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