mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
[ASEnvironment - Layout] Fixes to upward propagation of ASLayoutable properties.
This commit is contained in:
@@ -15,6 +15,4 @@
|
||||
|
||||
@property (strong, nonatomic) UIWindow *window;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -12,5 +12,4 @@
|
||||
#import "Post.h"
|
||||
|
||||
@implementation Post
|
||||
|
||||
@end
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -12,7 +12,4 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface ViewController : UIViewController
|
||||
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user