[ASEnvironment - Layout] Fixes to upward propagation of ASLayoutable properties.

This commit is contained in:
Hannah Troisi
2016-04-02 15:03:43 -07:00
parent a817abd43f
commit dbad1c38e5
12 changed files with 54 additions and 67 deletions

View File

@@ -15,6 +15,4 @@
@property (strong, nonatomic) UIWindow *window;
@end

View File

@@ -10,23 +10,17 @@
*/
#import "AppDelegate.h"
#import "ViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
[self.window makeKeyAndVisible];
return YES;
}
@end

View File

@@ -20,8 +20,8 @@
@implementation CommentsNode
- (instancetype)initWithCommentsCount:(NSInteger)comentsCount {
- (instancetype)initWithCommentsCount:(NSInteger)comentsCount
{
self = [super init];
if (self) {
_commentsCount = comentsCount;
@@ -44,8 +44,8 @@
}
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize {
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
{
ASStackLayoutSpec *mainStack = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal spacing:6.0 justifyContent:ASStackLayoutJustifyContentStart alignItems:ASStackLayoutAlignItemsCenter children:@[self.iconNode, self.countNode]];
// set sizeRange to make width fixed to 60
@@ -55,5 +55,4 @@
return [ASStaticLayoutSpec staticLayoutSpecWithChildren:@[mainStack]];
}
@end

View File

@@ -21,8 +21,8 @@
@implementation LikesNode
- (instancetype)initWithLikesCount:(NSInteger)likesCount {
- (instancetype)initWithLikesCount:(NSInteger)likesCount
{
self = [super init];
if (self) {
_likesCount = likesCount;
@@ -49,7 +49,7 @@
}
+ (BOOL) getYesOrNo
+ (BOOL)getYesOrNo
{
int tmp = (arc4random() % 30)+1;
if (tmp % 5 == 0) {
@@ -58,8 +58,8 @@
return NO;
}
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize {
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
{
ASStackLayoutSpec *mainStack = [ASStackLayoutSpec stackLayoutSpecWithDirection:ASStackLayoutDirectionHorizontal spacing:6.0 justifyContent:ASStackLayoutJustifyContentStart alignItems:ASStackLayoutAlignItemsCenter children:@[_iconNode, _countNode]];
// set sizeRange to make width fixed to 60
@@ -67,7 +67,6 @@
ASRelativeSize max = ASRelativeSizeMake(ASRelativeDimensionMakeWithPoints(60.0), ASRelativeDimensionMakeWithPoints(40.0));
mainStack.sizeRange = ASRelativeSizeRangeMake(min, max);
return [ASStaticLayoutSpec staticLayoutSpecWithChildren:@[mainStack]];
}
@end

View File

@@ -12,5 +12,4 @@
#import "Post.h"
@implementation Post
@end

View File

@@ -34,8 +34,8 @@
@implementation PostNode
- (instancetype)initWithPost:(Post *)post {
- (instancetype)initWithPost:(Post *)post
{
self = [super init];
if (self) {
_post = post;
@@ -181,14 +181,19 @@
[super didLoad];
}
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize {
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize
{
// Flexible spacer between username and time
ASLayoutSpec *spacer = [[ASLayoutSpec alloc] init];
spacer.flexGrow = YES;
// NOTE: This inset is not actually required by the layout, but is an example of the upward propogation of layoutable
// properties. Specifically, .flexGrow from the child is transferred to the inset spec so they can expand together.
// Without this capability, it would be required to set insetSpacer.flexGrow = YES;
ASInsetLayoutSpec *insetSpacer = [ASInsetLayoutSpec insetLayoutSpecWithInsets:UIEdgeInsetsMake(0, 0, 0, 0) child:spacer];
// Horizontal stack for name, username, via icon and time
NSMutableArray *layoutSpecChildren = [@[_nameNode, _usernameNode, spacer] mutableCopy];
NSMutableArray *layoutSpecChildren = [@[_nameNode, _usernameNode, insetSpacer] mutableCopy];
if (_post.via != 0) {
[layoutSpecChildren addObject:_viaNode];
}

View File

@@ -54,16 +54,16 @@
};
}
+ (NSDictionary *)cellControlStyle {
+ (NSDictionary *)cellControlStyle
{
return @{
NSFontAttributeName : [UIFont systemFontOfSize:13.0],
NSForegroundColorAttributeName: [UIColor lightGrayColor]
};
}
+ (NSDictionary *)cellControlColoredStyle {
+ (NSDictionary *)cellControlColoredStyle
{
return @{
NSFontAttributeName : [UIFont systemFontOfSize:13.0],
NSForegroundColorAttributeName: [UIColor colorWithRed:59.0/255.0 green:89.0/255.0 blue:152.0/255.0 alpha:1.0]

View File

@@ -12,7 +12,4 @@
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end

View File

@@ -45,8 +45,8 @@
_tableView.asyncDelegate = nil;
}
- (void)viewDidLoad {
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView = [[ASTableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain asyncDataFetching:YES];
@@ -57,8 +57,8 @@
[self.view addSubview:self.tableView];
}
- (void)createSocialAppDataSource {
- (void)createSocialAppDataSource
{
_socialAppDataSource = [[NSMutableArray alloc] init];
Post *newPost = [[Post alloc] init];