Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

Optional explicit vertical order in VerticalStackLayout #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UsefulBits/UIKit/VerticalStackLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

@property (nonatomic, assign) CGFloat padding;
@property (nonatomic, assign) UIEdgeInsets contentInsets;
@property (nonatomic, copy) NSArray *(^verticalOrder)(NSArray *subviews);

- (id)initWithPadding:(CGFloat)padding contentInsets:(UIEdgeInsets)insets;

Expand Down
8 changes: 6 additions & 2 deletions UsefulBits/UIKit/VerticalStackLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ - (id)initWithPadding:(CGFloat)padding contentInsets:(UIEdgeInsets)insets;
{
[self setPadding:padding];
[self setContentInsets:insets];
[self setVerticalOrder:^NSArray *(NSArray *subviews) {
return subviews;
}];
}

return self;
Expand All @@ -65,7 +68,8 @@ - (void)layout:(UIView *)view action:(void (^) (UIView *subview, CGRect subviewF
CGRect content_bounds = UIEdgeInsetsInsetRect([view bounds], [self contentInsets]);
CGFloat width = CGRectGetWidth(content_bounds);

CGFloat subview_height = [[[[view subviews] trunk] reduce: ^ id (id height, id subview) {
NSArray *ordered_views = [self verticalOrder]([view subviews]);
CGFloat subview_height = [[[ordered_views trunk] reduce: ^ id (id height, id subview) {
CGSize subview_size = [subview sizeThatFits:CGSizeMake(width, 0.)];
CGRect subview_frame = CGRectMake(CGRectGetMinX(content_bounds), [height floatValue], width, subview_size.height);

Expand All @@ -76,7 +80,7 @@ - (void)layout:(UIView *)view action:(void (^) (UIView *subview, CGRect subviewF
return [NSNumber numberWithFloat:bottom];
} initial:[NSNumber numberWithFloat:CGRectGetMinY(content_bounds)]] floatValue];

UIView *last = [[view subviews] last];
UIView *last = [ordered_views last];
CGSize last_size = [last sizeThatFits:CGSizeMake(width, 0.)];
CGRect last_frame = CGRectMake(CGRectGetMinX(content_bounds), subview_height, width, last_size.height);

Expand Down