forked from material-components/material-components-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDialogsTypicalUseExampleViewController.m
More file actions
152 lines (124 loc) · 5.75 KB
/
DialogsTypicalUseExampleViewController.m
File metadata and controls
152 lines (124 loc) · 5.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Copyright 2018-present the Material Components for iOS authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import <UIKit/UIKit.h>
#import "MaterialButtons.h"
#import "MaterialButtons+Theming.h"
#import "MaterialCollections.h"
#import "MaterialDialogs.h"
#import "MaterialDialogs+Theming.h"
#import "MaterialColorScheme.h"
#import "MaterialContainerScheme.h"
#import "MaterialTypographyScheme.h"
static NSString *const kTitleString = @"Reset Settings?";
static NSString *const kMessageString =
@"This will reset your device to its default factory settings.";
#pragma mark - DialogsTypicalUseExampleViewController
@interface DialogsTypicalUseExampleViewController : UIViewController
@property(nonatomic, strong, nullable) id<MDCContainerScheming> containerScheme;
@end
@implementation DialogsTypicalUseExampleViewController
- (instancetype)init {
self = [super init];
if (self) {
MDCContainerScheme *scheme = [[MDCContainerScheme alloc] init];
scheme.colorScheme =
[[MDCSemanticColorScheme alloc] initWithDefaults:MDCColorSchemeDefaultsMaterial201907];
scheme.typographyScheme =
[[MDCTypographyScheme alloc] initWithDefaults:MDCTypographySchemeDefaultsMaterial201902];
_containerScheme = scheme;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = self.containerScheme.colorScheme.backgroundColor;
MDCButton *defaultButton = [[MDCButton alloc] initWithFrame:CGRectZero];
defaultButton.translatesAutoresizingMaskIntoConstraints = NO;
[defaultButton setTitle:@"Material Alert" forState:UIControlStateNormal];
[defaultButton addTarget:self
action:@selector(showMaterialAlert:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:defaultButton];
[defaultButton applyTextThemeWithScheme:self.containerScheme];
MDCButton *emphasisButton = [[MDCButton alloc] initWithFrame:CGRectZero];
emphasisButton.translatesAutoresizingMaskIntoConstraints = NO;
[emphasisButton setTitle:@"Material Alert With Styled Actions" forState:UIControlStateNormal];
[emphasisButton addTarget:self
action:@selector(showStyledActionsAlert:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:emphasisButton];
[emphasisButton applyTextThemeWithScheme:self.containerScheme];
[self.view.centerXAnchor constraintEqualToAnchor:defaultButton.centerXAnchor].active = YES;
[self.view.centerYAnchor constraintEqualToAnchor:defaultButton.centerYAnchor].active = YES;
[self.view.centerXAnchor constraintEqualToAnchor:emphasisButton.centerXAnchor].active = YES;
[emphasisButton.topAnchor constraintEqualToAnchor:defaultButton.bottomAnchor constant:8.0f]
.active = YES;
}
- (void)showMaterialAlert:(UIButton *)button {
MDCAlertController *alert = [MDCAlertController alertControllerWithTitle:kTitleString
message:kMessageString];
alert.mdc_adjustsFontForContentSizeCategory = YES;
alert.enableRippleBehavior = YES;
MDCActionHandler handler = ^(MDCAlertAction *action) {
NSLog(@"action pressed: %@", action.title);
};
[alert addAction:[MDCAlertAction actionWithTitle:@"Accept" handler:handler]];
[alert addAction:[MDCAlertAction actionWithTitle:@"Cancel" handler:handler]];
[alert applyThemeWithScheme:self.containerScheme];
[self presentViewController:alert animated:YES completion:NULL];
}
- (void)showStyledActionsAlert:(UIButton *)button {
MDCAlertController *alert = [MDCAlertController alertControllerWithTitle:kTitleString
message:kMessageString];
alert.mdc_adjustsFontForContentSizeCategory = YES;
alert.enableRippleBehavior = YES;
MDCActionHandler handler = ^(MDCAlertAction *action) {
NSLog(@"action pressed: %@", action.title);
};
[alert addAction:[MDCAlertAction actionWithTitle:@"Accept"
emphasis:MDCActionEmphasisHigh
handler:handler]];
[alert addAction:[MDCAlertAction actionWithTitle:@"Cancel"
emphasis:MDCActionEmphasisMedium
handler:handler]];
[alert applyThemeWithScheme:self.containerScheme];
[self presentViewController:alert animated:YES completion:NULL];
}
@end
#pragma mark - DialogsTypicalUseExampleViewController - CatalogByConvention
@implementation DialogsTypicalUseExampleViewController (CatalogByConvention)
+ (NSDictionary *)catalogMetadata {
return @{
@"breadcrumbs" : @[ @"Dialogs", @"Dialogs (Catalog)" ],
@"description" : @"Dialogs inform users about a task and can contain critical information, "
@"require decisions, or involve multiple tasks.",
@"primaryDemo" : @YES,
@"presentable" : @YES,
};
}
@end
@implementation DialogsTypicalUseExampleViewController (SnapshotTestingByConvention)
- (void)testPresented {
if (self.presentedViewController) {
[self dismissViewControllerAnimated:NO completion:nil];
}
[self showMaterialAlert:nil];
}
- (void)testActionEmphasis {
if (self.presentedViewController) {
[self dismissViewControllerAnimated:NO completion:nil];
}
[self showStyledActionsAlert:nil];
}
@end