Skip to content

Commit 20cc047

Browse files
code hygiene
1 parent a929e2c commit 20cc047

2 files changed

Lines changed: 38 additions & 25 deletions

File tree

ABReleaseNotesViewController/ABReleaseNotesViewController.m

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
@interface ABReleaseNotesViewController ()<UIViewControllerTransitioningDelegate>
3434
@property(nonatomic,copy) NSString *appIdentifier;
3535
@property(nonatomic,strong) ABReleaseNotesDownloader *downloader;
36-
@property(nonatomic,strong) UIView *contentView;
36+
@property(nonatomic,strong) UIView *roundedCornerView;
3737
@property(nonatomic,strong) UIVisualEffectView *vibrancyView;
3838
@property(nonatomic,strong) UILabel *titleLabel;
3939
@property(nonatomic,strong) UITextView *bodyText;
@@ -82,7 +82,10 @@ - (void)commonInit {
8282
_closeButtonTitle = NSLocalizedString(@"Dismiss", @"");
8383

8484
_lineViewColor = [UIColor colorWithWhite:0.f alpha:0.25f];
85-
85+
86+
// this has to be created in the initializer to ensure that, when the release notes
87+
// content is retrieved from the iTunes API, there is already a text view available
88+
// to plug the content into.
8689
_bodyText = ({
8790
UITextView *textView = [[UITextView alloc] init];
8891
textView.translatesAutoresizingMaskIntoConstraints = NO;
@@ -99,24 +102,9 @@ - (void)commonInit {
99102
- (void)viewDidLoad {
100103
[super viewDidLoad];
101104

102-
self.contentView = [[UIView alloc] initWithFrame:self.view.bounds];
103-
self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
104-
self.contentView.clipsToBounds = YES;
105-
[self.view addSubview:self.contentView];
106-
107105
self.view.layer.shadowColor = [UIColor colorWithRed:0.f green:0.f blue:0.25f alpha:1.f].CGColor;
108106
self.view.layer.shadowOpacity = 0.25f;
109107
self.view.layer.shadowRadius = 8.f;
110-
self.view.layer.borderWidth = 1.f;
111-
self.view.layer.borderColor = self.lineViewColor.CGColor;
112-
[self createVisualEffectsViews];
113-
114-
UINavigationBar *navigationBar = [[UINavigationBar alloc] init];
115-
116-
NSString *title = self.mode == ABReleaseNotesViewControllerModeProduction ? self.title : [NSString stringWithFormat:@"TESTING - %@", self.title];
117-
[navigationBar pushNavigationItem:[[UINavigationItem alloc] initWithTitle:title] animated:YES];
118-
119-
UIView *bottomEdge = [self.class makeLineViewWithColor:self.lineViewColor];
120108

121109
UIButton *closeButton = ({
122110
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
@@ -129,16 +117,33 @@ - (void)viewDidLoad {
129117
button;
130118
});
131119

132-
NSArray *subviews = @[navigationBar, self.bodyText, bottomEdge, closeButton];
120+
NSString *title = self.mode == ABReleaseNotesViewControllerModeProduction ? self.title : [NSString stringWithFormat:@"TESTING - %@", self.title];
121+
UINavigationBar *navigationBar = [self createNavigationBarWithTitle:title];
122+
123+
NSArray *subviews = @[navigationBar, self.bodyText, [self.class makeLineViewWithColor:self.lineViewColor], closeButton];
133124

134-
UIStackView *stackView = [[UIStackView alloc] initWithArrangedSubviews:subviews];
135-
stackView.frame = self.vibrancyView.contentView.bounds;
136-
stackView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
137-
stackView.axis = UILayoutConstraintAxisVertical;
138-
[self.vibrancyView.contentView addSubview:stackView];
125+
[self createContainerViewsWithContentView:({
126+
UIStackView *stackView = [[UIStackView alloc] initWithArrangedSubviews:subviews];
127+
stackView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
128+
stackView.axis = UILayoutConstraintAxisVertical;
129+
stackView;
130+
})];
139131
}
140132

141-
- (void)createVisualEffectsViews {
133+
- (UINavigationBar*)createNavigationBarWithTitle:(NSString*)title {
134+
UINavigationBar *navigationBar = [[UINavigationBar alloc] init];
135+
[navigationBar pushNavigationItem:[[UINavigationItem alloc] initWithTitle:title] animated:YES];
136+
return navigationBar;
137+
}
138+
139+
- (void)createContainerViewsWithContentView:(UIView*)contentView {
140+
141+
self.roundedCornerView = [[UIView alloc] initWithFrame:self.view.bounds];
142+
self.roundedCornerView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
143+
self.roundedCornerView.clipsToBounds = YES;
144+
self.roundedCornerView.layer.cornerRadius = 8.f;
145+
[self.view addSubview:self.roundedCornerView];
146+
142147
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:self.blurEffectStyle];
143148

144149
UIVisualEffectView *background = ({
@@ -147,7 +152,7 @@ - (void)createVisualEffectsViews {
147152
effectView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
148153
effectView;
149154
});
150-
[self.contentView addSubview:background];
155+
[self.roundedCornerView addSubview:background];
151156

152157
self.vibrancyView = ({
153158
UIVisualEffectView *v = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
@@ -156,6 +161,9 @@ - (void)createVisualEffectsViews {
156161
v;
157162
});
158163
[background.contentView addSubview:self.vibrancyView];
164+
165+
contentView.frame = self.vibrancyView.contentView.bounds;
166+
[self.vibrancyView.contentView addSubview:contentView];
159167
}
160168

161169
#pragma mark - Actions

Demo/ViewController.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ - (void)viewDidLoad {
2727
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com"]]];
2828

2929
self.releaseNotes = [[ABReleaseNotesViewController alloc] initWithAppIdentifier:@"329380089"];
30+
31+
// if this was a real app, I would set the mode property on the release notes controller to 'production':
32+
// self.releaseNotes.mode = ABReleaseNotesViewControllerModeProduction;
33+
// It is set by default to ABReleaseNotesViewControllerModeTesting, which means that it always appears:
34+
self.releaseNotes.mode = ABReleaseNotesViewControllerModeTesting;
3035
}
3136

3237
- (void)viewDidAppear:(BOOL)animated {

0 commit comments

Comments
 (0)