From 4e8d8352808aaadb69ee8b2243b0a9470d84f19d Mon Sep 17 00:00:00 2001 From: Hannah Troisi Date: Thu, 14 Apr 2016 00:52:05 -0700 Subject: [PATCH] =?UTF-8?q?[ASDKgram=20example=20update]=20addressed=20PR?= =?UTF-8?q?=20comments=20-=20overrode=20the=20-(void)fetchData=20method=20?= =?UTF-8?q?in=20PhotoCellNode.m=20to=20download=20the=20photo=E2=80=99s=20?= =?UTF-8?q?comments.=20This=20method=20gets=20called=20with=20the=20PhotoC?= =?UTF-8?q?ellNode=20enters=20ASInterfaceStateFetchData,=20which=20is=20se?= =?UTF-8?q?t=20by=20the=20rangeController.=20=20=20=20=20-=20UIKIT=20COMPA?= =?UTF-8?q?RISON:=20I=20left=20the=20comment=20bulk=20download=20(for=20al?= =?UTF-8?q?l=20photos=20in=20a=20page=20load)=20in=20the=20PhotoFeedViewCo?= =?UTF-8?q?ntroller=20side=20for=20UIKit=20because=20when=20implemented=20?= =?UTF-8?q?in=20the=20PhotoTableViewCell,=20each=20cell=20jumped=20around?= =?UTF-8?q?=20as=20it=20changed=20size=20when=20it=20came=20on=20screen.?= =?UTF-8?q?=20-=20minor=20appearance=20updates=20=20=20=20=20-=20updated?= =?UTF-8?q?=20color=20scheme=20=20=20=20=20-=20fixed=20status=20bar=20styl?= =?UTF-8?q?e=20to=20darkBackgroundColor=20-=20cleaned=20up=20layoutSpecTha?= =?UTF-8?q?tFits:=20in=20PhotoCellNode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/ASDKgram/Sample/AppDelegate.m | 39 +++++------ examples/ASDKgram/Sample/CommentView.m | 2 +- examples/ASDKgram/Sample/CommentsNode.m | 6 +- examples/ASDKgram/Sample/Info.plist | 6 +- examples/ASDKgram/Sample/PhotoCellNode.h | 1 - examples/ASDKgram/Sample/PhotoCellNode.m | 65 +++++++++---------- .../ASDKgram/Sample/PhotoFeedNodeController.m | 38 +++++------ examples/ASDKgram/Sample/UserModel.h | 2 +- examples/ASDKgram/Sample/Utilities.m | 4 +- .../Sample/WindowWithStatusBarUnderlay.h | 2 + .../Sample/WindowWithStatusBarUnderlay.m | 8 +-- examples/ASDKgram/Sample/main.m | 6 -- 12 files changed, 86 insertions(+), 93 deletions(-) diff --git a/examples/ASDKgram/Sample/AppDelegate.m b/examples/ASDKgram/Sample/AppDelegate.m index dbb7233d37..0796a1b00d 100644 --- a/examples/ASDKgram/Sample/AppDelegate.m +++ b/examples/ASDKgram/Sample/AppDelegate.m @@ -22,14 +22,15 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - _window = [[WindowWithStatusBarUnderlay alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - _window.backgroundColor = [UIColor whiteColor]; + // this UIWindow subclass is neccessary to make the status bar opaque + _window = [[WindowWithStatusBarUnderlay alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + _window.backgroundColor = [UIColor whiteColor]; // UIKit Home Feed viewController & navController - PhotoFeedNodeController *asdkHomeFeedVC = [[PhotoFeedNodeController alloc] init]; - UINavigationController *asdkHomeFeedNavCtrl = [[UINavigationController alloc] initWithRootViewController:asdkHomeFeedVC]; - asdkHomeFeedNavCtrl.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"ASDK" image:[UIImage imageNamed:@"home"] tag:0]; - asdkHomeFeedNavCtrl.hidesBarsOnSwipe = YES; + PhotoFeedNodeController *asdkHomeFeedVC = [[PhotoFeedNodeController alloc] init]; + UINavigationController *asdkHomeFeedNavCtrl = [[UINavigationController alloc] initWithRootViewController:asdkHomeFeedVC]; + asdkHomeFeedNavCtrl.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"ASDK" image:[UIImage imageNamed:@"home"] tag:0]; + asdkHomeFeedNavCtrl.hidesBarsOnSwipe = YES; // ASDK Home Feed viewController & navController PhotoFeedViewController *uikitHomeFeedVC = [[PhotoFeedViewController alloc] init]; @@ -38,25 +39,21 @@ uikitHomeFeedNavCtrl.hidesBarsOnSwipe = YES; // UITabBarController - UITabBarController *tabBarController = [[UITabBarController alloc] init]; - tabBarController.viewControllers = @[uikitHomeFeedNavCtrl, asdkHomeFeedNavCtrl]; - tabBarController.selectedViewController = asdkHomeFeedNavCtrl; - tabBarController.delegate = self; - - // Nav Bar appearance - [[UINavigationBar appearance] setBarTintColor:[UIColor darkBlueColor]]; - [[UINavigationBar appearance] setTranslucent:NO]; - NSDictionary *attributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]}; - [[UINavigationBar appearance] setTitleTextAttributes:attributes]; - // make the status bar have white text (changes after scrolling, but not on initial app startup) - // UINavigationController does not forward on preferredStatusBarStyle calls to its child view controllers. - // Instead it manages its own state...http://stackoverflow.com/questions/19022210/preferredstatusbarstyle-isnt-called/19513714#19513714 - uikitHomeFeedNavCtrl.navigationBar.barStyle = UIBarStyleBlack; - asdkHomeFeedNavCtrl.navigationBar.barStyle = UIBarStyleBlack; + UITabBarController *tabBarController = [[UITabBarController alloc] init]; + tabBarController.viewControllers = @[uikitHomeFeedNavCtrl, asdkHomeFeedNavCtrl]; + tabBarController.selectedViewController = asdkHomeFeedNavCtrl; + tabBarController.delegate = self; + [[UITabBar appearance] setTintColor:[UIColor darkBlueColor]]; _window.rootViewController = tabBarController; [_window makeKeyAndVisible]; + // Nav Bar appearance + NSDictionary *attributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]}; + [[UINavigationBar appearance] setTitleTextAttributes:attributes]; + [[UINavigationBar appearance] setBarTintColor:[UIColor darkBlueColor]]; + [[UINavigationBar appearance] setTranslucent:NO]; + // iOS8 hides the status bar in landscape orientation, this forces the status bar hidden status to NO [application setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; [application setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone]; diff --git a/examples/ASDKgram/Sample/CommentView.m b/examples/ASDKgram/Sample/CommentView.m index c6c5f316eb..bf82e70f05 100644 --- a/examples/ASDKgram/Sample/CommentView.m +++ b/examples/ASDKgram/Sample/CommentView.m @@ -11,7 +11,7 @@ #import "Utilities.h" #define INTER_COMMENT_SPACING 5 -#define NUM_COMMENTS_TO_SHOW 3 +#define NUM_COMMENTS_TO_SHOW 3 @implementation CommentView { diff --git a/examples/ASDKgram/Sample/CommentsNode.m b/examples/ASDKgram/Sample/CommentsNode.m index c4e4d8e5ff..86d164eae8 100644 --- a/examples/ASDKgram/Sample/CommentsNode.m +++ b/examples/ASDKgram/Sample/CommentsNode.m @@ -9,7 +9,7 @@ #import "CommentsNode.h" #define INTER_COMMENT_SPACING 5 -#define NUM_COMMENTS_TO_SHOW 3 +#define NUM_COMMENTS_TO_SHOW 3 @implementation CommentsNode { @@ -52,7 +52,7 @@ int labelsIndex = 0; if (addViewAllCommentsLabel) { - commentLabelString = [_commentFeed viewAllCommentsAttributedString]; + commentLabelString = [_commentFeed viewAllCommentsAttributedString]; [[_commentNodes objectAtIndex:labelsIndex] setAttributedString:commentLabelString]; labelsIndex++; } @@ -90,7 +90,7 @@ for (NSUInteger i = 0; i < numLabelsToAdd; i++) { - ASTextNode *commentLabel = [[ASTextNode alloc] init]; + ASTextNode *commentLabel = [[ASTextNode alloc] init]; commentLabel.maximumNumberOfLines = 3; [_commentNodes addObject:commentLabel]; diff --git a/examples/ASDKgram/Sample/Info.plist b/examples/ASDKgram/Sample/Info.plist index 74faa7f503..22adc008a5 100644 --- a/examples/ASDKgram/Sample/Info.plist +++ b/examples/ASDKgram/Sample/Info.plist @@ -2,8 +2,6 @@ - UIViewControllerBasedStatusBarAppearance - CFBundleDevelopmentRegion en CFBundleExecutable @@ -32,6 +30,8 @@ armv7 + UIStatusBarStyle + UIStatusBarStyleLightContent UISupportedInterfaceOrientations UIInterfaceOrientationPortrait @@ -45,5 +45,7 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight + UIViewControllerBasedStatusBarAppearance + diff --git a/examples/ASDKgram/Sample/PhotoCellNode.h b/examples/ASDKgram/Sample/PhotoCellNode.h index 3f24103226..058fd812c3 100644 --- a/examples/ASDKgram/Sample/PhotoCellNode.h +++ b/examples/ASDKgram/Sample/PhotoCellNode.h @@ -15,6 +15,5 @@ @interface PhotoCellNode : ASCellNode - (instancetype)initWithPhotoObject:(PhotoModel *)photo; -- (void)loadCommentsForPhoto:(PhotoModel *)photo; @end diff --git a/examples/ASDKgram/Sample/PhotoCellNode.m b/examples/ASDKgram/Sample/PhotoCellNode.m index 6327bc3184..6c030a2917 100644 --- a/examples/ASDKgram/Sample/PhotoCellNode.m +++ b/examples/ASDKgram/Sample/PhotoCellNode.m @@ -74,17 +74,9 @@ } }]; - _photoTimeIntervalSincePostLabel = [[ASTextNode alloc] init]; - _photoTimeIntervalSincePostLabel.layerBacked = YES; - _photoTimeIntervalSincePostLabel.attributedString = [photo uploadDateAttributedStringWithFontSize:FONT_SIZE]; - - _photoLikesLabel = [[ASTextNode alloc] init]; - _photoLikesLabel.layerBacked = YES; - _photoLikesLabel.attributedString = [photo likesAttributedStringWithFontSize:FONT_SIZE]; - - _photoDescriptionLabel = [[ASTextNode alloc] init]; - _photoDescriptionLabel.layerBacked = YES; - _photoDescriptionLabel.attributedString = [photo descriptionAttributedStringWithFontSize:FONT_SIZE]; + _photoTimeIntervalSincePostLabel = [self createLayerBackedTextNodeWithString:[photo uploadDateAttributedStringWithFontSize:FONT_SIZE]]; + _photoLikesLabel = [self createLayerBackedTextNodeWithString:[photo likesAttributedStringWithFontSize:FONT_SIZE]]; + _photoDescriptionLabel = [self createLayerBackedTextNodeWithString:[photo descriptionAttributedStringWithFontSize:FONT_SIZE]]; _photoDescriptionLabel.maximumNumberOfLines = 3; _photoCommentsView = [[CommentsNode alloc] init]; @@ -110,12 +102,11 @@ - (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize { // username / photo location header vertical stack - _photoLocationLabel.flexShrink = YES; - _userNameLabel.flexShrink = YES; + _photoLocationLabel.flexShrink = YES; + _userNameLabel.flexShrink = YES; ASStackLayoutSpec *headerSubStack = [ASStackLayoutSpec verticalStackLayoutSpec]; - headerSubStack.flexShrink = YES; - + headerSubStack.flexShrink = YES; if (_photoLocationLabel.attributedString) { [headerSubStack setChildren:@[_userNameLabel, _photoLocationLabel]]; } else { @@ -125,56 +116,65 @@ // header stack _userAvatarImageView.preferredFrameSize = CGSizeMake(USER_IMAGE_HEIGHT, USER_IMAGE_HEIGHT); // constrain avatar image frame size - _photoTimeIntervalSincePostLabel.spacingBefore = HORIZONTAL_BUFFER; // to remove double spaces around spacer + _photoTimeIntervalSincePostLabel.spacingBefore = HORIZONTAL_BUFFER; // to remove double spaces around spacer - ASLayoutSpec *spacer = [[ASLayoutSpec alloc] init]; // FIXME: long locations overflow post time - set max size? - spacer.flexGrow = YES; - spacer.flexShrink = YES; + ASLayoutSpec *spacer = [[ASLayoutSpec alloc] init]; // FIXME: long locations overflow post time - set max size? + spacer.flexGrow = YES; + + UIEdgeInsets avatarInsets = UIEdgeInsetsMake(HORIZONTAL_BUFFER, 0, HORIZONTAL_BUFFER, HORIZONTAL_BUFFER); + ASInsetLayoutSpec *avatarInset = [ASInsetLayoutSpec insetLayoutSpecWithInsets:avatarInsets child:_userAvatarImageView]; ASStackLayoutSpec *headerStack = [ASStackLayoutSpec horizontalStackLayoutSpec]; headerStack.alignItems = ASStackLayoutAlignItemsCenter; // center items vertically in horizontal stack headerStack.justifyContent = ASStackLayoutJustifyContentStart; // justify content to the left side of the header stack - - UIEdgeInsets avatarInsets = UIEdgeInsetsMake(HORIZONTAL_BUFFER, 0, HORIZONTAL_BUFFER, HORIZONTAL_BUFFER); - ASInsetLayoutSpec *avatarInset = [ASInsetLayoutSpec insetLayoutSpecWithInsets:avatarInsets child:_userAvatarImageView]; - - headerStack.flexShrink = YES; - [headerStack setChildren:@[avatarInset, headerSubStack, spacer, _photoTimeIntervalSincePostLabel]]; // header inset stack - UIEdgeInsets insets = UIEdgeInsetsMake(0, HORIZONTAL_BUFFER, 0, HORIZONTAL_BUFFER); ASInsetLayoutSpec *headerWithInset = [ASInsetLayoutSpec insetLayoutSpecWithInsets:insets child:headerStack]; - headerWithInset.flexShrink = YES; // footer stack - ASStackLayoutSpec *footerStack = [ASStackLayoutSpec verticalStackLayoutSpec]; footerStack.spacing = VERTICAL_BUFFER; - [footerStack setChildren:@[_photoLikesLabel, _photoDescriptionLabel, _photoCommentsView]]; // footer inset stack - UIEdgeInsets footerInsets = UIEdgeInsetsMake(VERTICAL_BUFFER, HORIZONTAL_BUFFER, VERTICAL_BUFFER, HORIZONTAL_BUFFER); ASInsetLayoutSpec *footerWithInset = [ASInsetLayoutSpec insetLayoutSpecWithInsets:footerInsets child:footerStack]; // vertical stack - CGFloat cellWidth = constrainedSize.max.width; _photoImageView.preferredFrameSize = CGSizeMake(cellWidth, cellWidth); // constrain photo frame size ASStackLayoutSpec *verticalStack = [ASStackLayoutSpec verticalStackLayoutSpec]; verticalStack.alignItems = ASStackLayoutAlignItemsStretch; // stretch headerStack to fill horizontal space [verticalStack setChildren:@[headerWithInset, _photoImageView, footerWithInset]]; - verticalStack.flexShrink = YES; return verticalStack; } #pragma mark - Instance Methods +- (void)fetchData +{ + [super fetchData]; + + [_photoModel.commentFeed refreshFeedWithCompletionBlock:^(NSArray *newComments) { + [self loadCommentsForPhoto:_photoModel]; + }]; +} + +#pragma mark - Helper Methods + +- (ASTextNode *)createLayerBackedTextNodeWithString:(NSAttributedString *)attributedString +{ + ASTextNode *textNode = [[ASTextNode alloc] init]; + textNode.layerBacked = YES; + textNode.attributedString = attributedString; + + return textNode; +} + - (void)loadCommentsForPhoto:(PhotoModel *)photo { if (photo.commentFeed.numberOfItemsInFeed > 0) { @@ -184,5 +184,4 @@ } } - @end diff --git a/examples/ASDKgram/Sample/PhotoFeedNodeController.m b/examples/ASDKgram/Sample/PhotoFeedNodeController.m index 16f08ad50e..4eb9247bc9 100644 --- a/examples/ASDKgram/Sample/PhotoFeedNodeController.m +++ b/examples/ASDKgram/Sample/PhotoFeedNodeController.m @@ -80,7 +80,7 @@ [_activityIndicatorView stopAnimating]; [self insertNewRowsInTableView:newPhotos]; - [self requestCommentsForPhotos:newPhotos]; +// [self requestCommentsForPhotos:newPhotos]; // immediately start second larger fetch [self loadPageWithContext:nil]; @@ -93,30 +93,30 @@ [_photoFeed requestPageWithCompletionBlock:^(NSArray *newPhotos){ [self insertNewRowsInTableView:newPhotos]; - [self requestCommentsForPhotos:newPhotos]; +// [self requestCommentsForPhotos:newPhotos]; if (context) { [context completeBatchFetching:YES]; } } numResultsToReturn:20]; } -- (void)requestCommentsForPhotos:(NSArray *)newPhotos -{ - for (PhotoModel *photo in newPhotos) { - [photo.commentFeed refreshFeedWithCompletionBlock:^(NSArray *newComments) { - - NSInteger rowNum = [_photoFeed indexOfPhotoModel:photo]; - NSIndexPath *cellPath = [NSIndexPath indexPathForRow:rowNum inSection:0]; - PhotoCellNode *cell = (PhotoCellNode *)[_tableNode.view nodeForRowAtIndexPath:cellPath]; - - if (cell) { - [cell loadCommentsForPhoto:photo]; - [_tableNode.view beginUpdates]; - [_tableNode.view endUpdates]; - } - }]; - } -} +//- (void)requestCommentsForPhotos:(NSArray *)newPhotos +//{ +// for (PhotoModel *photo in newPhotos) { +// [photo.commentFeed refreshFeedWithCompletionBlock:^(NSArray *newComments) { +// +// NSInteger rowNum = [_photoFeed indexOfPhotoModel:photo]; +// NSIndexPath *cellPath = [NSIndexPath indexPathForRow:rowNum inSection:0]; +// PhotoCellNode *cell = (PhotoCellNode *)[_tableNode.view nodeForRowAtIndexPath:cellPath]; +// +// if (cell) { +// [cell loadCommentsForPhoto:photo]; +// [_tableNode.view beginUpdates]; +// [_tableNode.view endUpdates]; +// } +// }]; +// } +//} - (void)insertNewRowsInTableView:(NSArray *)newPhotos { diff --git a/examples/ASDKgram/Sample/UserModel.h b/examples/ASDKgram/Sample/UserModel.h index 9595ce0415..4190c3612e 100644 --- a/examples/ASDKgram/Sample/UserModel.h +++ b/examples/ASDKgram/Sample/UserModel.h @@ -8,7 +8,7 @@ @interface UserModel : NSObject -@property (nonatomic, assign, readonly) NSDictionary *dictionaryRepresentation; +@property (nonatomic, strong, readonly) NSDictionary *dictionaryRepresentation; @property (nonatomic, assign, readonly) NSUInteger userID; @property (nonatomic, strong, readonly) NSString *username; @property (nonatomic, strong, readonly) NSString *firstName; diff --git a/examples/ASDKgram/Sample/Utilities.m b/examples/ASDKgram/Sample/Utilities.m index 06de1c1ea5..9f25c1975b 100644 --- a/examples/ASDKgram/Sample/Utilities.m +++ b/examples/ASDKgram/Sample/Utilities.m @@ -14,12 +14,12 @@ + (UIColor *)darkBlueColor { - return [UIColor colorWithRed:18.0/255.0 green:86.0/255.0 blue:136.0/255.0 alpha:1.0]; + return [UIColor colorWithRed:70.0/255.0 green:102.0/255.0 blue:118.0/255.0 alpha:1.0]; } + (UIColor *)lightBlueColor { - return [UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0]; + return [UIColor colorWithRed:70.0/255.0 green:165.0/255.0 blue:196.0/255.0 alpha:1.0]; } @end diff --git a/examples/ASDKgram/Sample/WindowWithStatusBarUnderlay.h b/examples/ASDKgram/Sample/WindowWithStatusBarUnderlay.h index d822c78c10..bb3af4ce7e 100644 --- a/examples/ASDKgram/Sample/WindowWithStatusBarUnderlay.h +++ b/examples/ASDKgram/Sample/WindowWithStatusBarUnderlay.h @@ -6,6 +6,8 @@ // Copyright © 2016 Facebook. All rights reserved. // + +// this subclass is neccessary to make the status bar have an opaque, colored background @interface WindowWithStatusBarUnderlay : UIWindow @end diff --git a/examples/ASDKgram/Sample/WindowWithStatusBarUnderlay.m b/examples/ASDKgram/Sample/WindowWithStatusBarUnderlay.m index a521cfa50a..3e8f5a46b7 100644 --- a/examples/ASDKgram/Sample/WindowWithStatusBarUnderlay.m +++ b/examples/ASDKgram/Sample/WindowWithStatusBarUnderlay.m @@ -31,10 +31,10 @@ [self bringSubviewToFront:_statusBarOpaqueUnderlayView]; - _statusBarOpaqueUnderlayView.frame = CGRectMake(0, - 0, - [[UIScreen mainScreen] bounds].size.width, - [[UIApplication sharedApplication] statusBarFrame].size.height); + CGRect statusBarFrame = CGRectZero; + statusBarFrame.size.width = [[UIScreen mainScreen] bounds].size.width; + statusBarFrame.size.height = [[UIApplication sharedApplication] statusBarFrame].size.height; + _statusBarOpaqueUnderlayView.frame = statusBarFrame; } @end diff --git a/examples/ASDKgram/Sample/main.m b/examples/ASDKgram/Sample/main.m index 9162b66dc9..97769ec676 100644 --- a/examples/ASDKgram/Sample/main.m +++ b/examples/ASDKgram/Sample/main.m @@ -1,9 +1,3 @@ - - - - - - // main.m // ASDKgram //