Skip to content

Commit b78ccf7

Browse files
committed
Pesto: Init + wire up settings VC.
Summary: This commit introduces a VC for the settings view within the Pesto demo app. The settings VC is presented modally when a user taps the "Settings" item from the side menu. The actual settings VC is not implemented, rather just a dummy settings cell that can be used for design feedback + POC. Test Plan: 1. Open the Pesto demo app 2. Open the side menu 3. Tap "Settings" 4. Observe the settings VC is presented modally. 5. Rotate the device 6. Observe the dummy settings "cell" adapts to the rotation. Reviewers: #material_components_ios_owners, junius Reviewed By: #material_components_ios_owners, junius Projects: #material_components_ios Differential Revision: http://codereview.cc/D88
1 parent 2774715 commit b78ccf7

File tree

7 files changed

+282
-96
lines changed

7 files changed

+282
-96
lines changed

demos/Pesto/Pesto.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
C9A8552B1C4EDFAA003CADF7 /* PestoSettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C9A8552A1C4EDFAA003CADF7 /* PestoSettingsViewController.m */; };
1011
CE6A9B25D9A958C060ABB21D /* libPods-Pesto.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B0D8C7972AFCDCD5C9447F8E /* libPods-Pesto.a */; };
1112
DE381E1A1C457CEE00019C1D /* PestoCardCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = DE381E191C457CEE00019C1D /* PestoCardCollectionViewCell.m */; };
1213
DE381E401C45A9FB00019C1D /* PestoSideView.m in Sources */ = {isa = PBXBuildFile; fileRef = DE381E3F1C45A9FB00019C1D /* PestoSideView.m */; };
@@ -22,6 +23,8 @@
2223
/* Begin PBXFileReference section */
2324
B0D8C7972AFCDCD5C9447F8E /* libPods-Pesto.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Pesto.a"; sourceTree = BUILT_PRODUCTS_DIR; };
2425
BD25922DF748FCA11BCF30C4 /* Pods-Pesto.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Pesto.release.xcconfig"; path = "Pods/Target Support Files/Pods-Pesto/Pods-Pesto.release.xcconfig"; sourceTree = "<group>"; };
26+
C9A855291C4EDFAA003CADF7 /* PestoSettingsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PestoSettingsViewController.h; sourceTree = "<group>"; };
27+
C9A8552A1C4EDFAA003CADF7 /* PestoSettingsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PestoSettingsViewController.m; sourceTree = "<group>"; };
2528
D36B00D81356A416449940A7 /* Pods-Pesto.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Pesto.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Pesto/Pods-Pesto.debug.xcconfig"; sourceTree = "<group>"; };
2629
DE381E181C457CE300019C1D /* PestoCardCollectionViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PestoCardCollectionViewCell.h; sourceTree = "<group>"; };
2730
DE381E191C457CEE00019C1D /* PestoCardCollectionViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PestoCardCollectionViewCell.m; sourceTree = "<group>"; };
@@ -105,6 +108,8 @@
105108
DE381E3F1C45A9FB00019C1D /* PestoSideView.m */,
106109
DEBEDF2D1C3EF5D5004B614B /* PestoViewController.h */,
107110
DEBEDF2E1C3EF5D5004B614B /* PestoViewController.m */,
111+
C9A855291C4EDFAA003CADF7 /* PestoSettingsViewController.h */,
112+
C9A8552A1C4EDFAA003CADF7 /* PestoSettingsViewController.m */,
108113
DEBEDF271C3EF5D5004B614B /* Supporting Files */,
109114
);
110115
path = Pesto;
@@ -239,6 +244,7 @@
239244
isa = PBXSourcesBuildPhase;
240245
buildActionMask = 2147483647;
241246
files = (
247+
C9A8552B1C4EDFAA003CADF7 /* PestoSettingsViewController.m in Sources */,
242248
DEBEDF2F1C3EF5D5004B614B /* PestoViewController.m in Sources */,
243249
DE381E1A1C457CEE00019C1D /* PestoCardCollectionViewCell.m in Sources */,
244250
DE5EF8671C404E0E00D2D4B9 /* PestoDetailViewController.m in Sources */,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#import <UIKit/UIKit.h>
2+
3+
@interface PestoSettingsViewController : UIViewController
4+
@end
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#import "PestoSettingsViewController.h"
2+
3+
#import "MaterialSwitch.h"
4+
#import "MaterialTypography.h"
5+
6+
static CGFloat kPestoSettingsViewControllerCellViewInset = 20.f;
7+
static CGFloat kPestoSettingsViewControllerCellViewHeight = 48.f;
8+
9+
@interface PestoSettingsViewControllerCellView : UIView
10+
11+
@property(nonatomic) NSString *labelText;
12+
@property(nonatomic) BOOL on;
13+
14+
@end
15+
16+
@interface PestoSettingsViewControllerCellView ()
17+
18+
@property(nonatomic) UILabel *labelView;
19+
@property(nonatomic) MDCSwitch *switchView;
20+
21+
@end
22+
23+
@implementation PestoSettingsViewControllerCellView
24+
25+
- (id)initWithCoder:(NSCoder *)aDecoder {
26+
self = [super initWithCoder:aDecoder];
27+
return self;
28+
}
29+
30+
- (id)initWithFrame:(CGRect)frame {
31+
self = [super initWithFrame:frame];
32+
if (self) {
33+
CGRect descRect = CGRectMake(0, 0, self.bounds.size.width * 0.75f, self.bounds.size.height);
34+
_labelView = [[UILabel alloc] initWithFrame:descRect];
35+
_labelView.font = [MDCTypography body1Font];
36+
_labelView.alpha = [MDCTypography body1FontOpacity];
37+
_labelView.autoresizingMask = UIViewAutoresizingFlexibleWidth |
38+
UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin;
39+
40+
_switchView = [[MDCSwitch alloc] initWithFrame:CGRectZero];
41+
CGFloat switchX = self.bounds.size.width - _switchView.frame.size.width;
42+
CGFloat switchY = (self.bounds.size.height - _switchView.frame.size.height) / 2.f;
43+
_switchView.frame = CGRectOffset(_switchView.frame, switchX, switchY);
44+
_switchView.onTintColor = [UIColor colorWithRed:0.09f green:0.54f blue:0.44f alpha:1.f];
45+
_switchView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin |
46+
UIViewAutoresizingFlexibleTopMargin |
47+
UIViewAutoresizingFlexibleBottomMargin;
48+
49+
[self addSubview:_labelView];
50+
[self addSubview:_switchView];
51+
}
52+
return self;
53+
}
54+
55+
- (void)setLabelText:(NSString *)labelText {
56+
_labelText = labelText;
57+
_labelView.text = _labelText;
58+
[self setNeedsLayout];
59+
}
60+
61+
- (void)setOn:(BOOL)on {
62+
_on = on;
63+
_switchView.on = on;
64+
}
65+
66+
@end
67+
68+
@implementation PestoSettingsViewController
69+
70+
- (void)viewDidLoad {
71+
[super viewDidLoad];
72+
CGRect testViewFrame = CGRectMake(0,
73+
10.f,
74+
self.view.bounds.size.width,
75+
kPestoSettingsViewControllerCellViewHeight);
76+
CGRect insetFrame = CGRectInset(testViewFrame, kPestoSettingsViewControllerCellViewInset, 0);
77+
PestoSettingsViewControllerCellView *testCellView = [[PestoSettingsViewControllerCellView alloc]
78+
initWithFrame:insetFrame];
79+
testCellView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
80+
testCellView.labelText = @"Settings view needs more work?";
81+
testCellView.on = YES;
82+
83+
self.view.backgroundColor = [UIColor whiteColor];
84+
85+
[self.view addSubview:testCellView];
86+
}
87+
88+
@end

demos/Pesto/Pesto/PestoSideView.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
#import <UIKit/UIKit.h>
22

3+
@class PestoSideView;
4+
@protocol PestoSideViewDelegate <NSObject>
5+
6+
@optional
7+
- (void)sideViewDidSelectSettings:(PestoSideView *)sideView;
8+
9+
@end
10+
311
@interface PestoSideView : UIView
412

13+
@property(weak) id<PestoSideViewDelegate> delegate;
14+
515
- (void)showSideView;
616

717
- (void)hideSideView;

demos/Pesto/Pesto/PestoSideView.m

Lines changed: 66 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
@interface PestoSideViewCollectionViewCell : UICollectionViewCell
1717

18-
@property (nonatomic) NSString *title;
18+
@property(nonatomic) NSString *title;
1919

2020
@end
2121

@@ -24,7 +24,6 @@ @implementation PestoSideViewCollectionViewCell
2424
- (id)initWithFrame:(CGRect)frame {
2525
self = [super initWithFrame:frame];
2626
if (self) {
27-
2827
}
2928
return self;
3029
}
@@ -50,19 +49,29 @@ - (void)prepareForReuse {
5049

5150
@end
5251

52+
@class PestoSideContentView;
53+
@protocol PestoSideContentViewDelegate <NSObject>
54+
55+
@optional
56+
- (void)sideContentView:(PestoSideContentView *)sideContentView
57+
didSelectItemWithTitle:(NSString *)title;
58+
59+
@end
60+
5361
@interface PestoSideContentView : UIView <UICollectionViewDataSource,
5462
UICollectionViewDelegateFlowLayout>
5563

56-
@property (nonatomic) NSArray *titles;
57-
@property (nonatomic) NSCache *imageCache;
58-
@property (nonatomic) UICollectionView *collectionView;
64+
@property(nonatomic) NSArray *titles;
65+
@property(nonatomic) NSCache *imageCache;
66+
@property(nonatomic) UICollectionView *collectionView;
67+
@property(weak) id<PestoSideContentViewDelegate> delegate;
5968

6069
@end
6170

6271
@implementation PestoSideContentView
6372

6473
- (void)layoutSubviews {
65-
_titles = @[ @"Home", @"Favorite", @"Saved", @"Trending", @"Settings" ];
74+
_titles = @[ @"Home", @"Favorite", @"Saved", @"Trending", @"Settings" ];
6675

6776
CGRect avatarRect = CGRectMake(0, 0, kPestoSideViewAvatarDim, kPestoSideViewAvatarDim);
6877
NSString *imageURL = [kPestoSideViewWidthBaseURL stringByAppendingString:@"avatar.jpg"];
@@ -138,7 +147,7 @@ - (UIImageView *)imageViewWithURL:(NSString *)url {
138147
dispatch_async(dispatch_get_global_queue(0, 0), ^{
139148
NSData *imageData = [_imageCache objectForKey:url];
140149
if (!imageData) {
141-
imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:url]];
150+
imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:url]];
142151
[_imageCache setObject:imageData forKey:url];
143152
}
144153
if (imageData == nil) {
@@ -156,7 +165,7 @@ + (Class)layerClass {
156165
return [MDCShadowLayer class];
157166
}
158167

159-
# pragma mark - UICollectionViewDataSource
168+
#pragma mark - UICollectionViewDataSource
160169

161170
- (NSInteger)collectionView:(UICollectionView *)collectionView
162171
numberOfItemsInSection:(NSInteger)section {
@@ -174,26 +183,30 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
174183
return cell;
175184
}
176185

186+
#pragma mark - UICollectionViewDelegateFlowLayout
187+
177188
- (void)collectionView:(UICollectionView *)collectionView
178189
didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
190+
if (self.delegate &&
191+
[self.delegate respondsToSelector:@selector(sideContentView:didSelectItemWithTitle:)]) {
192+
[self.delegate sideContentView:self didSelectItemWithTitle:_titles[[indexPath row]]];
193+
}
179194
}
180195

181-
# pragma mark - UICollectionViewDelegateFlowLayout
182-
183196
- (CGSize)collectionView:(UICollectionView *)collectionView
184-
layout:(UICollectionViewLayout*)collectionViewLayout
197+
layout:(UICollectionViewLayout *)collectionViewLayout
185198
sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
186199
return CGSizeMake(collectionView.bounds.size.width, 40.f);
187200
}
188201

189202
@end
190203

191-
@interface PestoSideView () <UIGestureRecognizerDelegate>
204+
@interface PestoSideView () <UIGestureRecognizerDelegate, PestoSideContentViewDelegate>
192205

193-
@property (nonatomic) CGFloat xDelta;
194-
@property (nonatomic) CGFloat xStart;
195-
@property (nonatomic) PestoSideContentView *contentView;
196-
@property (nonatomic) UIButton *dismissButton;
206+
@property(nonatomic) CGFloat xDelta;
207+
@property(nonatomic) CGFloat xStart;
208+
@property(nonatomic) PestoSideContentView *contentView;
209+
@property(nonatomic) UIButton *dismissButton;
197210

198211
@end
199212

@@ -206,12 +219,15 @@ - (id)initWithFrame:(CGRect)frame {
206219
CGRectMake(-kPestoSideViewWidth, 0, kPestoSideViewWidth, self.frame.size.height);
207220
_contentView = [[PestoSideContentView alloc] initWithFrame:contentViewFrame];
208221
_contentView.backgroundColor = [UIColor whiteColor];
222+
_contentView.delegate = self;
209223
[self addSubview:_contentView];
210224

211225
UITapGestureRecognizer *tapRecognizer =
212226
[[UITapGestureRecognizer alloc] initWithTarget:self
213227
action:@selector(hideSideView)];
228+
tapRecognizer.delegate = self;
214229
[self addGestureRecognizer:tapRecognizer];
230+
215231
UIPanGestureRecognizer *panRecognizer =
216232
[[UIPanGestureRecognizer alloc] initWithTarget:self
217233
action:@selector(panGestureRecognized:)];
@@ -230,31 +246,39 @@ - (void)layoutSubviews {
230246

231247
- (void)showSideView {
232248
[UIView animateWithDuration:kPestoSideViewAnimationDuration
233-
delay:0
234-
options:UIViewAnimationOptionCurveEaseOut
235-
animations:^ {
236-
_contentView.transform = [PestoSideView showTransform];
237-
} completion:^(BOOL finished) {
238-
239-
}];
249+
delay:0
250+
options:UIViewAnimationOptionCurveEaseOut
251+
animations:^{
252+
_contentView.transform = [PestoSideView showTransform];
253+
}
254+
completion:^(BOOL finished){
255+
256+
}];
240257
}
241258

242259
- (void)hideSideView {
243260
[UIView animateWithDuration:kPestoSideViewAnimationDuration
244-
delay:0
245-
options:UIViewAnimationOptionCurveEaseOut
246-
animations:^ {
247-
_contentView.transform = [PestoSideView hideTransform];
248-
} completion:^(BOOL finished) {
249-
self.hidden = YES;
250-
}];
261+
delay:0
262+
options:UIViewAnimationOptionCurveEaseOut
263+
animations:^{
264+
_contentView.transform = [PestoSideView hideTransform];
265+
}
266+
completion:^(BOOL finished) {
267+
self.hidden = YES;
268+
}];
251269
}
252270

253271
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
254272
shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
255273
return YES;
256274
}
257275

276+
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
277+
shouldReceiveTouch:(UITouch *)touch {
278+
return [gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]] &&
279+
![touch.view isDescendantOfView:_contentView];
280+
}
281+
258282
- (void)panGestureRecognized:(UIPanGestureRecognizer *)recognizer {
259283
CGPoint tappedPoint = [recognizer locationInView:self];
260284
CGFloat xCoordinate = tappedPoint.x;
@@ -288,4 +312,16 @@ + (CGAffineTransform)hideTransform {
288312
return CGAffineTransformIdentity;
289313
}
290314

315+
#pragma mark - PestoSideContentViewDelegate
316+
317+
- (void)sideContentView:(PestoSideContentView *)sideContentView
318+
didSelectItemWithTitle:(NSString *)title {
319+
if (self.delegate) {
320+
if ([title isEqualToString:@"Settings"] &&
321+
[self.delegate respondsToSelector:@selector(sideViewDidSelectSettings:)]) {
322+
[self.delegate sideViewDidSelectSettings:self];
323+
}
324+
}
325+
}
326+
291327
@end

0 commit comments

Comments
 (0)