Repository navigation
Expand file tree
/
Copy pathKBErrorView.m
More file actions
64 lines (49 loc) · 1.94 KB
/
Copy pathKBErrorView.m
File metadata and controls
64 lines (49 loc) · 1.94 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
//
// KBErrorView.m
// Keybase
//
// Created by Gabriel on 3/6/15.
// Copyright (c) 2015 Gabriel Handford. All rights reserved.
//
#import "KBErrorView.h"
@interface KBErrorView ()
@property KBLabel *label;
@property KBLabel *descriptionLabel;
@property KBButton *closeButton;
@end
@implementation KBErrorView
- (void)viewInit {
[super viewInit];
[self kb_setBackgroundColor:KBAppearance.currentAppearance.dangerBackgroundColor];
_label = [KBLabel label];
[self addSubview:_label];
_descriptionLabel = [KBLabel label];
[self addSubview:_descriptionLabel];
_closeButton = [KBButton buttonWithText:@"Close" style:KBButtonStyleDefault];
[self addSubview:_closeButton];
YOSelf yself = self;
self.viewLayout = [YOLayout layoutWithLayoutBlock:^CGSize(id<YOLayout> layout, CGSize size) {
CGFloat y = 20;
y += [layout sizeToFitVerticalInFrame:CGRectMake(20, y, size.width - 40, 0) view:yself.label].size.height + 20;
if ([yself.descriptionLabel hasText]) {
y += -10;
y += [layout sizeToFitVerticalInFrame:CGRectMake(20, y, size.width - 40, 0) view:yself.descriptionLabel].size.height + 20;
}
if (!yself.closeButton.hidden) {
y += [layout centerWithSize:CGSizeMake(120, 0) frame:CGRectMake(0, y, size.width, 0) view:yself.closeButton].size.height + 20;
}
return CGSizeMake(size.width, y);
}];
}
- (void)setError:(NSError *)error completion:(dispatch_block_t)completion {
[_label setText:error.localizedDescription style:KBTextStyleDefault options:KBTextOptionsDanger alignment:NSCenterTextAlignment lineBreakMode:NSLineBreakByWordWrapping];
[_descriptionLabel setText:error.localizedRecoverySuggestion style:KBTextStyleSecondaryText options:KBTextOptionsDanger alignment:NSCenterTextAlignment lineBreakMode:NSLineBreakByWordWrapping];
if (completion) {
_closeButton.targetBlock = completion;
_closeButton.hidden = NO;
} else {
_closeButton.hidden = YES;
}
[self setNeedsLayout];
}
@end