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.4 release
Browse files Browse the repository at this point in the history
  • Loading branch information
davdroman committed Sep 2, 2015
1 parent 9da76aa commit c33c1d6
Show file tree
Hide file tree
Showing 16 changed files with 239 additions and 67 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.3"
s.version = "3.0.0-alpha.4"
s.summary = "Settings screen composing framework"
s.homepage = "https://github.com/DavdRoman/Bohr"
s.author = { "David Román" => "[email protected]" }
Expand Down
12 changes: 12 additions & 0 deletions Bohr.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
D5CF66521B8E491A00FC5F13 /* UIColor+Bohr.m in Sources */ = {isa = PBXBuildFile; fileRef = D5CF66511B8E491A00FC5F13 /* UIColor+Bohr.m */; };
D5D00B6E1B8FD14500ADCAB2 /* OptionsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D5D00B6D1B8FD14500ADCAB2 /* OptionsTableViewController.m */; };
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 = (); }; };
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 Expand Up @@ -122,6 +125,9 @@
D5D00B6C1B8FD14500ADCAB2 /* OptionsTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OptionsTableViewController.h; sourceTree = "<group>"; };
D5D00B6D1B8FD14500ADCAB2 /* OptionsTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OptionsTableViewController.m; sourceTree = "<group>"; };
D5D00B711B8FE63E00ADCAB2 /* BOTableViewCell+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "BOTableViewCell+Private.h"; sourceTree = "<group>"; };
D5D499F01B9749AB0015C617 /* BOTextTableViewCell+Subclass.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "BOTextTableViewCell+Subclass.h"; sourceTree = "<group>"; };
D5EBE5EF1B963C250096AD4C /* BONumberTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BONumberTableViewCell.h; sourceTree = "<group>"; };
D5EBE5F01B963C250096AD4C /* BONumberTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BONumberTableViewCell.m; sourceTree = "<group>"; };
D5F1D8A81B3A1EF1004DA018 /* BOTableViewController+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "BOTableViewController+Private.h"; sourceTree = "<group>"; };
D5F1D8AA1B3A210E004DA018 /* BOSetting+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "BOSetting+Private.h"; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -211,6 +217,9 @@
754E568C1B1FC16700075B6E /* BOSwitchTableViewCell.m */,
75E02FE11B21F72C009698D3 /* BOTextTableViewCell.h */,
75E02FE21B21F72C009698D3 /* BOTextTableViewCell.m */,
D5D499F01B9749AB0015C617 /* BOTextTableViewCell+Subclass.h */,
D5EBE5EF1B963C250096AD4C /* BONumberTableViewCell.h */,
D5EBE5F01B963C250096AD4C /* BONumberTableViewCell.m */,
D594623A1B90E17D0028F4BD /* BODateTableViewCell.h */,
D594623B1B90E17D0028F4BD /* BODateTableViewCell.m */,
D594623E1B90EA5F0028F4BD /* UILabel+DatePickerCustomization.h */,
Expand Down Expand Up @@ -248,11 +257,13 @@
files = (
D5F1D8AB1B3A210E004DA018 /* BOSetting+Private.h in Headers */,
D59462401B90EA5F0028F4BD /* UILabel+DatePickerCustomization.h in Headers */,
D5EBE5F11B963C250096AD4C /* BONumberTableViewCell.h in Headers */,
754E56501B1B461700075B6E /* BOTableViewCell+Subclass.h in Headers */,
75E19B461B2BCCFE00C03FF6 /* BOTextTableViewCell.h in Headers */,
75C7AE041B1AB3280050C8AA /* Bohr.h in Headers */,
75C7AE211B1AB3480050C8AA /* BOTableViewController.h in Headers */,
75E19B441B2BC76100C03FF6 /* BOChoiceTableViewCell.h in Headers */,
D5D499F21B9749AB0015C617 /* BOTextTableViewCell+Subclass.h in Headers */,
754E56891B1DFDB400075B6E /* BOSetting.h in Headers */,
D5CF66461B8DFAC800FC5F13 /* BOTableViewSection.h in Headers */,
D5CF664C1B8DFF4700FC5F13 /* MZAppearance.h in Headers */,
Expand Down Expand Up @@ -383,6 +394,7 @@
files = (
75C7AE2A1B1AB42A0050C8AA /* BOTableViewCell.m in Sources */,
75C7AE221B1AB3480050C8AA /* BOTableViewController.m in Sources */,
D5EBE5F21B963C250096AD4C /* BONumberTableViewCell.m in Sources */,
754E568A1B1DFDB400075B6E /* BOSetting.m in Sources */,
75B6CE1F1B375DCA00DADCBD /* BOButtonTableViewCell.m in Sources */,
D5CF66471B8DFAC800FC5F13 /* BOTableViewSection.m in Sources */,
Expand Down
3 changes: 3 additions & 0 deletions Bohr/BODateTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

@interface BODateTableViewCell : BOTableViewCell

/// The date format used for the displayed text on the right side of the cell.
@property (nonatomic, assign) NSString *dateFormat;

/// The date picker used by the cell to manipulate its setting value.
@property (nonatomic) UIDatePicker *datePicker;

@end
15 changes: 8 additions & 7 deletions Bohr/BODateTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,27 @@ - (void)setup {
self.expansionView = self.datePicker;

self.dateFormatter = [NSDateFormatter new];
self.dateFormatter.dateFormat = [self defaultDateFormat];
self.dateFormatter.dateFormat = [self dateFormat];
}

- (CGFloat)expansionHeight {
return 216;
}

- (void)setDateFormat:(NSString *)dateFormat {
dateFormat = self.dateFormat.length == 0 ? [self defaultDateFormat] : dateFormat;
self.dateFormatter.dateFormat = dateFormat;
if (dateFormat.length > 0) {
self.dateFormatter.dateFormat = dateFormat;
}
}

- (NSString *)dateFormat {
if (self.dateFormatter.dateFormat.length == 0) {
return [NSDateFormatter dateFormatFromTemplate:@"dd/MM/YYYY" options:kNilOptions locale:[NSLocale currentLocale]];
}

return self.dateFormatter.dateFormat;
}

- (NSString *)defaultDateFormat {
return [NSDateFormatter dateFormatFromTemplate:@"dd/MM/YYYY" options:kNilOptions locale:[NSLocale currentLocale]];
}

- (void)settingValueDidChange {
self.detailTextLabel.text = [self.dateFormatter stringFromDate:self.setting.value];
self.datePicker.date = self.setting.value;
Expand Down
16 changes: 16 additions & 0 deletions Bohr/BONumberTableViewCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// BONumberTableViewCell.h
// Bohr
//
// Created by David Román Aguirre on 01/09/15.
//
//

#import "BOTextTableViewCell.h"

@interface BONumberTableViewCell : BOTextTableViewCell

/// The maximum number of decimals shown in the text field.
@property (nonatomic) NSInteger numberOfDecimals;

@end
67 changes: 67 additions & 0 deletions Bohr/BONumberTableViewCell.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// BONumberTableViewCell.m
// Bohr
//
// Created by David Román Aguirre on 01/09/15.
//
//

#import "BONumberTableViewCell.h"

#import "BOTableViewCell+Subclass.h"
#import "BOTextTableViewCell+Subclass.h"

@implementation NSNumber (String)

- (NSString *)stringWithDecimals:(NSInteger)decimals {
NSNumberFormatter *formatter = [NSNumberFormatter new];
formatter.locale = [NSLocale currentLocale];
formatter.maximumFractionDigits = decimals;
return [formatter stringFromNumber:self];
}

@end

@implementation NSString (Number)

- (BOOL)isNumeric {
if (self.length > 0) {
NSScanner *scanner = [NSScanner scannerWithString:self];
scanner.locale = [NSLocale currentLocale];
return [scanner scanDecimal:nil] && scanner.atEnd;
}

return YES;
}

- (NSNumber *)number {
NSNumberFormatter *formatter = [NSNumberFormatter new];
formatter.locale = [NSLocale currentLocale];
return [formatter numberFromString:self];
}

@end

@implementation BONumberTableViewCell

- (void)setup {
[super setup];

self.textField.keyboardType = UIKeyboardTypeDecimalPad;
}

- (void)settingValueDidChange {
self.textField.text = [self.setting.value stringWithDecimals:self.numberOfDecimals];
}

#pragma mark UITextFieldDelegate

- (BOTextFieldInputError)validateTextFieldInput:(NSString *)input {
return ![input isNumeric] ? BOTextFieldInputNotNumericError : [super validateTextFieldInput:input];
}

- (id)settingValueForInput:(NSString *)input {
return [input number];
}

@end

This file was deleted.

3 changes: 2 additions & 1 deletion Bohr/BOTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ - (instancetype)initWithTitle:(NSString *)title key:(NSString *)key handler:(voi
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self setup];
if (handler) handler(self);
self.preservesSuperviewLayoutMargins = NO;
self.clipsToBounds = YES;
self.textLabel.numberOfLines = 0;
self.textLabel.text = title;
Expand All @@ -33,7 +34,7 @@ - (instancetype)initWithTitle:(NSString *)title key:(NSString *)key handler:(voi

- (void)didMoveToSuperview {
if (self.expansionView && !self.expansionView.superview) {
[self.contentView addSubview:self.expansionView];
[self addSubview:self.expansionView];

NSLayoutConstraint *topConstraint = [NSLayoutConstraint constraintWithItem:self.expansionView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.expansionView.superview attribute:NSLayoutAttributeTopMargin multiplier:1 constant:0];
NSLayoutConstraint *leftConstraint = [NSLayoutConstraint constraintWithItem:self.expansionView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.expansionView.superview attribute:NSLayoutAttributeLeft multiplier:1 constant:0];
Expand Down
45 changes: 35 additions & 10 deletions Bohr/BOTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,7 @@ - (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 = [cell.contentView systemLayoutSizeFittingSize:CGSizeMake(cell.contentView.frame.size.width, UITableViewAutomaticDimension)].height;

if (cellHeight < self.tableView.estimatedRowHeight) {
cellHeight = self.tableView.estimatedRowHeight;
} else {
cellHeight += 10;
}
CGFloat cellHeight = MAX(self.tableView.estimatedRowHeight, [self heightForCell:cell]);

cell.layoutMargins = UIEdgeInsetsMake(cellHeight, cell.layoutMargins.left, cell.layoutMargins.bottom, cell.layoutMargins.right);

Expand All @@ -117,6 +111,22 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
return cellHeight;
}

- (CGFloat)heightForCell:(UITableViewCell *)cell {

UITableViewCell *cleanCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cleanCell.layoutMargins = cell.layoutMargins;
cleanCell.frame = cell.frame;
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;

return height;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
BOTableViewSection *section = self.sections[indexPath.section];
BOTableViewCell *cell = section.cells[indexPath.row];
Expand All @@ -138,8 +148,10 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

- (void)reloadTableView {
[UIView performWithoutAnimation:^{
CGPoint previousContentOffset = self.tableView.contentOffset;
[self.tableView beginUpdates];
[self.tableView endUpdates];
self.tableView.contentOffset = previousContentOffset;
}];
}

Expand Down Expand Up @@ -187,6 +199,10 @@ - (NSArray *)footerViews {
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
UITableViewHeaderFooterView *footerView = self.footerViews[section];
footerView.textLabel.text = [self tableView:tableView titleForFooterInSection:section];
footerView.textLabel.numberOfLines = 0;
CGPoint previousOrigin = footerView.textLabel.frame.origin;
[footerView sizeToFit];
footerView.textLabel.frame = CGRectMake(previousOrigin.x, previousOrigin.y, footerView.textLabel.frame.size.width, footerView.textLabel.frame.size.height);

return footerView.intrinsicContentSize.height;
}
Expand All @@ -211,9 +227,12 @@ - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInte
return footerTitle ? footerTitle : @"";
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UITableViewHeaderFooterView *footerView = self.footerViews[section];
return footerView;
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)sectionIndex {
UITableViewHeaderFooterView *footerView = self.footerViews[sectionIndex];
if (![[self tableView:tableView titleForFooterInSection:sectionIndex] isEqualToString:@""]) {
return footerView;
}
return nil;
}

- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UITableViewHeaderFooterView *)footerView forSection:(NSInteger)sectionIndex {
Expand All @@ -222,6 +241,12 @@ - (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
7 changes: 7 additions & 0 deletions Bohr/BOTableViewSection.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ + (instancetype)appearance {
- (instancetype)init {
if (self = [super init]) {
self.cells = [NSArray new];
// Workaround to UITableViewHeaderFooterView's default 0-sized font driving iOS 9 nuts (yeah, WTF Apple).
self.footerTitleFont = [UIFont fontWithName:@"Helvetica" size:13];
// I mean, really, if you...
// NSLog(@"%@", [UITableViewHeaderFooterView new].textLabel.font);
// you get "font-size: 0.00pt".
// Your documentation for fontWithName:size: says EXPLICITLY "this value must be greater than 0.0.".
// Again, WTF Apple.
[[[self class] appearance] applyInvocationTo:self];
}

Expand Down
27 changes: 27 additions & 0 deletions Bohr/BOTextTableViewCell+Subclass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// BOTextTableViewCell+Subclass.h
// Bohr
//
// Created by David Román Aguirre on 02/09/15.
//
//

#import <Bohr/Bohr.h>

@interface BOTextTableViewCell (Subclass)

/**
* Validation method implemented by a BOTextTableViewCell class in order to check for possible errors in its input.
* @param filteredInput The input string with whitespace and new line characters trimmed.
* @return Some BOTextFieldInputError, or BOTextFieldInputNoError if there's no error with input.
*/
- (BOTextFieldInputError)validateTextFieldInput:(NSString *)input;

/**
* Conversion method implemented by a BOTextTableViewCell class in order to make any necessary transformations to the input before assigning it as a setting value.
* @param input The input string.
* @return Some object resulting from the transformation of the input.
*/
- (id)settingValueForInput:(NSString *)input;

@end
6 changes: 4 additions & 2 deletions Bohr/BOTextTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

#import "BOTableViewCell.h"

/// Defines an error after trying to input some new value to the cell text field.
/// Defines an error ocurred after trying to input some new value to the cell text field.
typedef NS_ENUM(NSInteger, BOTextFieldInputError) {
BOTextFieldInputTooShortError
BOTextFieldInputNoError,
BOTextFieldInputTooShortError,
BOTextFieldInputNotNumericError,
};

@interface BOTextTableViewCell : BOTableViewCell <UITextFieldDelegate>
Expand Down
Loading

0 comments on commit c33c1d6

Please sign in to comment.