Skip to content
This repository has been archived by the owner on Aug 24, 2020. It is now read-only.

Commit

Permalink
3.0.0-alpha.5
Browse files Browse the repository at this point in the history
  • Loading branch information
davdroman committed Sep 3, 2015
1 parent c33c1d6 commit eb49174
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Bohr.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Bohr"
s.version = "3.0.0-alpha.4"
s.version = "3.0.0-alpha.5"
s.summary = "Settings screen composing framework"
s.homepage = "https://github.com/DavdRoman/Bohr"
s.author = { "David Román" => "[email protected]" }
Expand Down
2 changes: 1 addition & 1 deletion Bohr.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
D5D00B721B8FE63E00ADCAB2 /* BOTableViewCell+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = D5D00B711B8FE63E00ADCAB2 /* BOTableViewCell+Private.h */; };
D5D499F21B9749AB0015C617 /* BOTextTableViewCell+Subclass.h in Headers */ = {isa = PBXBuildFile; fileRef = D5D499F01B9749AB0015C617 /* BOTextTableViewCell+Subclass.h */; settings = {ATTRIBUTES = (Private, ); }; };
D5EBE5F11B963C250096AD4C /* BONumberTableViewCell.h in Headers */ = {isa = PBXBuildFile; fileRef = D5EBE5EF1B963C250096AD4C /* BONumberTableViewCell.h */; settings = {ATTRIBUTES = (Public, ); }; };
D5EBE5F21B963C250096AD4C /* BONumberTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D5EBE5F01B963C250096AD4C /* BONumberTableViewCell.m */; settings = {ASSET_TAGS = (); }; };
D5EBE5F21B963C250096AD4C /* BONumberTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D5EBE5F01B963C250096AD4C /* BONumberTableViewCell.m */; };
D5F1D8A91B3A1EF1004DA018 /* BOTableViewController+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = D5F1D8A81B3A1EF1004DA018 /* BOTableViewController+Private.h */; };
D5F1D8AB1B3A210E004DA018 /* BOSetting+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = D5F1D8AA1B3A210E004DA018 /* BOSetting+Private.h */; };
/* End PBXBuildFile section */
Expand Down
2 changes: 2 additions & 0 deletions Bohr/BOTableViewCell+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

@interface BOTableViewCell ()

@property (nonatomic) CGFloat height;

- (void)_updateAppearance;

@end
27 changes: 21 additions & 6 deletions Bohr/BOTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
#import "BOSetting+Private.h"
#import "BOTableViewController+Private.h"

@interface BOTableViewCell ()

@property (nonatomic) NSLayoutConstraint *expansionViewTopConstraint;

@end

@implementation BOTableViewCell

- (instancetype)initWithTitle:(NSString *)title key:(NSString *)key handler:(void (^)(id cell))handler {
Expand All @@ -32,17 +38,26 @@ - (instancetype)initWithTitle:(NSString *)title key:(NSString *)key handler:(voi
return self;
}

- (void)didMoveToSuperview {
if (self.expansionView && !self.expansionView.superview) {
[self addSubview:self.expansionView];
- (void)setExpansionView:(UIView *)expansionView {
if (self.expansionView != expansionView) {
[self.expansionView removeFromSuperview];
_expansionView = expansionView;
[self.contentView addSubview:self.expansionView];

NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:self.expansionView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.expansionView.superview attribute:NSLayoutAttributeTopMargin multiplier:1 constant:0];
self.expansionViewTopConstraint = [NSLayoutConstraint constraintWithItem:self.expansionView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.expansionView.superview attribute:NSLayoutAttributeTop multiplier:1 constant:0];
NSLayoutConstraint *leftConstraint = [NSLayoutConstraint constraintWithItem:self.expansionView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.expansionView.superview attribute:NSLayoutAttributeLeft multiplier:1 constant:0];
NSLayoutConstraint *rightConstraint = [NSLayoutConstraint constraintWithItem:self.expansionView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.expansionView.superview attribute:NSLayoutAttributeRight multiplier:1 constant:0];
NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:self.expansionView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:[self expansionHeight]];

self.expansionView.translatesAutoresizingMaskIntoConstraints = NO;
[self.expansionView.superview addConstraints:@[topConstraint, leftConstraint, rightConstraint, heightConstraint]];
[self.expansionView.superview addConstraints:@[self.expansionViewTopConstraint, leftConstraint, rightConstraint, heightConstraint]];
}
}

- (void)setHeight:(CGFloat)height {
if (_height != height) {
_height = height;
self.expansionViewTopConstraint.constant = height;
}
}

Expand All @@ -61,7 +76,7 @@ - (void)layoutSubviews {
[super layoutSubviews];

if ([self expansionHeight] > 0) {
CGFloat yOffset = (self.layoutMargins.top-self.frame.size.height)/2;
CGFloat yOffset = (self.height-self.frame.size.height)/2;

self.textLabel.center = CGPointMake(self.textLabel.center.x, self.textLabel.center.y+yOffset);
self.detailTextLabel.center = CGPointMake(self.detailTextLabel.center.x, self.detailTextLabel.center.y+yOffset);
Expand Down
31 changes: 14 additions & 17 deletions Bohr/BOTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
BOTableViewSection *section = self.sections[indexPath.section];
BOTableViewCell *cell = section.cells[indexPath.row];
CGFloat cellHeight = MAX(self.tableView.estimatedRowHeight, [self heightForCell:cell]);

cell.layoutMargins = UIEdgeInsetsMake(cellHeight, cell.layoutMargins.left, cell.layoutMargins.bottom, cell.layoutMargins.right);
CGFloat cellHeight = MAX(self.tableView.estimatedRowHeight, [self heightForCell:cell]);
cell.height = cellHeight;

if ([self.expansionIndexPath isEqual:indexPath]) {
cellHeight += [cell expansionHeight];
Expand All @@ -114,15 +114,13 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
- (CGFloat)heightForCell:(UITableViewCell *)cell {

UITableViewCell *cleanCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cleanCell.layoutMargins = cell.layoutMargins;
cleanCell.frame = cell.frame;
cleanCell.frame = CGRectMake(0, 0, cell.frame.size.width, 0);
cleanCell.textLabel.numberOfLines = 0;
cleanCell.textLabel.text = cell.textLabel.text;
cleanCell.detailTextLabel.text = cell.detailTextLabel.text;
cleanCell.accessoryView = cell.accessoryView;
cleanCell.accessoryType = cell.accessoryType;

CGFloat height = [cleanCell systemLayoutSizeFittingSize:CGSizeMake(cleanCell.frame.size.width, UITableViewAutomaticDimension)].height;
CGFloat height = [cleanCell systemLayoutSizeFittingSize:cleanCell.frame.size].height;

return height;
}
Expand All @@ -133,13 +131,17 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell.indexPath = indexPath;

if (cell.setting && !cell.setting.valueDidChangeBlock) {
[UIView performWithoutAnimation:^{
__unsafe_unretained typeof(self) weakSelf = self;
__unsafe_unretained typeof(cell) weakCell = cell;
cell.setting.valueDidChangeBlock = ^{
__unsafe_unretained typeof(self) weakSelf = self;
__unsafe_unretained typeof(cell) weakCell = cell;
cell.setting.valueDidChangeBlock = ^{
dispatch_async(dispatch_get_main_queue(), ^{
[weakCell settingValueDidChange];
[weakSelf reloadTableView];
};
});
};

[UIView performWithoutAnimation:^{
[cell settingValueDidChange];
}];
}

Expand Down Expand Up @@ -199,6 +201,7 @@ - (NSArray *)footerViews {
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
UITableViewHeaderFooterView *footerView = self.footerViews[section];
footerView.textLabel.text = [self tableView:tableView titleForFooterInSection:section];
// Super hacky code for iOS 9 support.
footerView.textLabel.numberOfLines = 0;
CGPoint previousOrigin = footerView.textLabel.frame.origin;
[footerView sizeToFit];
Expand Down Expand Up @@ -241,12 +244,6 @@ - (void)tableView:(UITableView *)tableView willDisplayFooterView:(UITableViewHea
if (section.footerTitleFont) footerView.textLabel.font = section.footerTitleFont;
}

- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
[self.tableView reloadData];
}];
}

#pragma mark Subclassing

- (void)setup {}
Expand Down

0 comments on commit eb49174

Please sign in to comment.