Repository navigation
Expand file tree
/
Copy pathKBStatusView.m
More file actions
95 lines (71 loc) · 3.28 KB
/
Copy pathKBStatusView.m
File metadata and controls
95 lines (71 loc) · 3.28 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
//
// KBStatusView.m
// Keybase
//
// Created by Gabriel on 3/6/15.
// Copyright (c) 2015 Gabriel Handford. All rights reserved.
//
#import "KBStatusView.h"
#import <YOLayout/YOLayout+PrefabLayouts.h>
@interface KBStatusView ()
@property KBLabel *titleLabel;
@property KBLabel *label;
@property KBLabel *descriptionLabel;
@property YOHBox *buttons;
@end
@implementation KBStatusView
- (void)viewInit {
[super viewInit];
[self kb_setBackgroundColor:KBAppearance.currentAppearance.backgroundColor];
YOView *contentView = [YOView view];
{
_titleLabel = [KBLabel label];
[contentView addSubview:_titleLabel];
_label = [KBLabel label];
[contentView addSubview:_label];
_descriptionLabel = [KBLabel label];
[contentView addSubview:_descriptionLabel];
_buttons = [YOHBox box:@{@"horizontalAlignment": @"center", @"spacing": @(10)}];
[contentView addSubview:_buttons];
YOSelf yself = self;
contentView.viewLayout = [YOLayout layoutWithLayoutBlock:^CGSize(id<YOLayout> layout, CGSize size) {
CGFloat y = yself.insets.top;
y += [layout sizeToFitVerticalInFrame:CGRectMake(yself.insets.left, y, size.width - yself.insets.left - yself.insets.right, 0) view:yself.titleLabel].size.height + 40;
y += [layout sizeToFitVerticalInFrame:CGRectMake(yself.insets.left, y, size.width - yself.insets.left - yself.insets.right, 0) view:yself.label].size.height + 20;
if ([yself.descriptionLabel hasText]) {
y += -10;
y += [layout sizeToFitVerticalInFrame:CGRectMake(yself.insets.left, y, size.width - yself.insets.left - yself.insets.right, 0) view:yself.descriptionLabel].size.height + 20;
}
if ([yself.buttons.subviews count] > 0) {
y += 20;
y += [layout sizeToFitVerticalInFrame:CGRectMake(0, y, size.width, 0) view:yself.buttons].size.height;
}
y += yself.insets.bottom;
return CGSizeMake(size.width, y);
}];
}
[self addSubview:contentView];
self.viewLayout = [YOLayout center:contentView];
}
- (void)viewDidAppear:(BOOL)animated { }
- (void)setError:(NSError *)error title:(NSString *)title retry:(dispatch_block_t)retry close:(dispatch_block_t)close {
[self setText:error.localizedDescription description:error.localizedRecoverySuggestion title:title retry:retry close:close];
}
- (void)setText:(NSString *)text description:(NSString *)description title:(NSString *)title retry:(dispatch_block_t)retry close:(dispatch_block_t)close {
[_titleLabel setText:title style:KBTextStyleHeaderLarge options:0 alignment:NSCenterTextAlignment lineBreakMode:NSLineBreakByWordWrapping];
[_label setText:text style:KBTextStyleDefault options:0 alignment:NSCenterTextAlignment lineBreakMode:NSLineBreakByWordWrapping];
[_descriptionLabel setText:description style:KBTextStyleDefault options:0 alignment:NSCenterTextAlignment lineBreakMode:NSLineBreakByWordWrapping];
[_buttons kb_removeAllSubviews];
if (retry) {
KBButton *retryButton = [KBButton buttonWithText:@"Retry" style:KBButtonStylePrimary];
retryButton.targetBlock = retry;
[_buttons addSubview:retryButton];
}
if (close) {
KBButton *closeButton = [KBButton buttonWithText:@"Close" style:KBButtonStyleDefault];
closeButton.targetBlock = close;
[_buttons addSubview:closeButton];
}
[self setNeedsLayout];
}
@end