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.2 release
Browse files Browse the repository at this point in the history
  • Loading branch information
davdroman committed Aug 28, 2015
1 parent a30fc70 commit 28b11c1
Show file tree
Hide file tree
Showing 14 changed files with 268 additions and 164 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.1"
s.version = "3.0.0-alpha.2"
s.summary = "Settings screen composing framework"
s.homepage = "https://github.com/DavdRoman/Bohr"
s.author = { "David Román" => "d@vidroman.me" }
Expand Down
24 changes: 20 additions & 4 deletions Bohr.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
75E19B451B2BC76100C03FF6 /* BOChoiceTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 754E56A31B20D2FE00075B6E /* BOChoiceTableViewCell.m */; };
75E19B461B2BCCFE00C03FF6 /* BOTextTableViewCell.h in Headers */ = {isa = PBXBuildFile; fileRef = 75E02FE11B21F72C009698D3 /* BOTextTableViewCell.h */; settings = {ATTRIBUTES = (Public, ); }; };
75E19B471B2BCCFE00C03FF6 /* BOTextTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 75E02FE21B21F72C009698D3 /* BOTextTableViewCell.m */; };
D594623C1B90E17D0028F4BD /* BODateTableViewCell.h in Headers */ = {isa = PBXBuildFile; fileRef = D594623A1B90E17D0028F4BD /* BODateTableViewCell.h */; settings = {ATTRIBUTES = (Public, ); }; };
D594623D1B90E17D0028F4BD /* BODateTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D594623B1B90E17D0028F4BD /* BODateTableViewCell.m */; };
D59462401B90EA5F0028F4BD /* UILabel+DatePickerCustomization.h in Headers */ = {isa = PBXBuildFile; fileRef = D594623E1B90EA5F0028F4BD /* UILabel+DatePickerCustomization.h */; };
D59462411B90EA5F0028F4BD /* UILabel+DatePickerCustomization.m in Sources */ = {isa = PBXBuildFile; fileRef = D594623F1B90EA5F0028F4BD /* UILabel+DatePickerCustomization.m */; };
D5CF66461B8DFAC800FC5F13 /* BOTableViewSection.h in Headers */ = {isa = PBXBuildFile; fileRef = D5CF66441B8DFAC800FC5F13 /* BOTableViewSection.h */; settings = {ATTRIBUTES = (Public, ); }; };
D5CF66471B8DFAC800FC5F13 /* BOTableViewSection.m in Sources */ = {isa = PBXBuildFile; fileRef = D5CF66451B8DFAC800FC5F13 /* BOTableViewSection.m */; };
D5CF664C1B8DFF4700FC5F13 /* MZAppearance.h in Headers */ = {isa = PBXBuildFile; fileRef = D5CF66481B8DFF4700FC5F13 /* MZAppearance.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -103,6 +107,10 @@
75C7AE261B1AB42A0050C8AA /* BOTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BOTableViewCell.m; sourceTree = "<group>"; };
75E02FE11B21F72C009698D3 /* BOTextTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BOTextTableViewCell.h; sourceTree = "<group>"; };
75E02FE21B21F72C009698D3 /* BOTextTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BOTextTableViewCell.m; sourceTree = "<group>"; };
D594623A1B90E17D0028F4BD /* BODateTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BODateTableViewCell.h; sourceTree = "<group>"; };
D594623B1B90E17D0028F4BD /* BODateTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BODateTableViewCell.m; sourceTree = "<group>"; };
D594623E1B90EA5F0028F4BD /* UILabel+DatePickerCustomization.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UILabel+DatePickerCustomization.h"; sourceTree = "<group>"; };
D594623F1B90EA5F0028F4BD /* UILabel+DatePickerCustomization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UILabel+DatePickerCustomization.m"; sourceTree = "<group>"; };
D5CF66441B8DFAC800FC5F13 /* BOTableViewSection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BOTableViewSection.h; sourceTree = "<group>"; };
D5CF66451B8DFAC800FC5F13 /* BOTableViewSection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BOTableViewSection.m; sourceTree = "<group>"; };
D5CF66481B8DFF4700FC5F13 /* MZAppearance.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MZAppearance.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -191,6 +199,10 @@
D5F1D8A81B3A1EF1004DA018 /* BOTableViewController+Private.h */,
D5CF66441B8DFAC800FC5F13 /* BOTableViewSection.h */,
D5CF66451B8DFAC800FC5F13 /* BOTableViewSection.m */,
D5CF66481B8DFF4700FC5F13 /* MZAppearance.h */,
D5CF66491B8DFF4700FC5F13 /* MZAppearance.m */,
D5CF664A1B8DFF4700FC5F13 /* NSInvocation+Copy.h */,
D5CF664B1B8DFF4700FC5F13 /* NSInvocation+Copy.m */,
75C7AE251B1AB42A0050C8AA /* BOTableViewCell.h */,
75C7AE261B1AB42A0050C8AA /* BOTableViewCell.m */,
D5D00B711B8FE63E00ADCAB2 /* BOTableViewCell+Private.h */,
Expand All @@ -199,6 +211,10 @@
754E568C1B1FC16700075B6E /* BOSwitchTableViewCell.m */,
75E02FE11B21F72C009698D3 /* BOTextTableViewCell.h */,
75E02FE21B21F72C009698D3 /* BOTextTableViewCell.m */,
D594623A1B90E17D0028F4BD /* BODateTableViewCell.h */,
D594623B1B90E17D0028F4BD /* BODateTableViewCell.m */,
D594623E1B90EA5F0028F4BD /* UILabel+DatePickerCustomization.h */,
D594623F1B90EA5F0028F4BD /* UILabel+DatePickerCustomization.m */,
754E56931B2083DE00075B6E /* BOTimeTableViewCell.h */,
754E56941B2083DE00075B6E /* BOTimeTableViewCell.m */,
754E56A21B20D2FE00075B6E /* BOChoiceTableViewCell.h */,
Expand All @@ -210,10 +226,6 @@
754E56871B1DFDB400075B6E /* BOSetting.h */,
754E56881B1DFDB400075B6E /* BOSetting.m */,
D5F1D8AA1B3A210E004DA018 /* BOSetting+Private.h */,
D5CF66481B8DFF4700FC5F13 /* MZAppearance.h */,
D5CF66491B8DFF4700FC5F13 /* MZAppearance.m */,
D5CF664A1B8DFF4700FC5F13 /* NSInvocation+Copy.h */,
D5CF664B1B8DFF4700FC5F13 /* NSInvocation+Copy.m */,
75C7AE011B1AB3280050C8AA /* Supporting Files */,
);
path = Bohr;
Expand All @@ -235,6 +247,7 @@
buildActionMask = 2147483647;
files = (
D5F1D8AB1B3A210E004DA018 /* BOSetting+Private.h in Headers */,
D59462401B90EA5F0028F4BD /* UILabel+DatePickerCustomization.h in Headers */,
754E56501B1B461700075B6E /* BOTableViewCell+Subclass.h in Headers */,
75E19B461B2BCCFE00C03FF6 /* BOTextTableViewCell.h in Headers */,
75C7AE041B1AB3280050C8AA /* Bohr.h in Headers */,
Expand All @@ -251,6 +264,7 @@
759E1B001B2BC31700AD8F38 /* BOTimeTableViewCell.h in Headers */,
75B6CE1E1B375DCA00DADCBD /* BOButtonTableViewCell.h in Headers */,
D5F1D8A91B3A1EF1004DA018 /* BOTableViewController+Private.h in Headers */,
D594623C1B90E17D0028F4BD /* BODateTableViewCell.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -373,7 +387,9 @@
75B6CE1F1B375DCA00DADCBD /* BOButtonTableViewCell.m in Sources */,
D5CF66471B8DFAC800FC5F13 /* BOTableViewSection.m in Sources */,
754E568E1B1FC16700075B6E /* BOSwitchTableViewCell.m in Sources */,
D594623D1B90E17D0028F4BD /* BODateTableViewCell.m in Sources */,
759E1B011B2BC31700AD8F38 /* BOTimeTableViewCell.m in Sources */,
D59462411B90EA5F0028F4BD /* UILabel+DatePickerCustomization.m in Sources */,
D5CF664D1B8DFF4700FC5F13 /* MZAppearance.m in Sources */,
75B6CE1D1B3756D800DADCBD /* BOOptionTableViewCell.m in Sources */,
75E19B471B2BCCFE00C03FF6 /* BOTextTableViewCell.m in Sources */,
Expand Down
16 changes: 16 additions & 0 deletions Bohr/BODateTableViewCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// BODateTableViewCell.h
// Bohr
//
// Created by David Román Aguirre on 28/08/15.
//
//

#import "BOTableViewCell.h"

@interface BODateTableViewCell : BOTableViewCell

@property (nonatomic, assign) NSString *dateFormat;
@property (nonatomic) UIDatePicker *datePicker;

@end
61 changes: 61 additions & 0 deletions Bohr/BODateTableViewCell.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// BODateTableViewCell.m
// Bohr
//
// Created by David Román Aguirre on 28/08/15.
//
//

#import "BODateTableViewCell.h"

#import "BOTableViewCell+Subclass.h"
#import "UILabel+DatePickerCustomization.h"

@interface BODateTableViewCell ()

@property (nonatomic) NSDateFormatter *dateFormatter;

@end

@implementation BODateTableViewCell

- (void)setup {
self.datePicker = [UIDatePicker new];
self.datePicker.backgroundColor = [UIColor clearColor];
self.datePicker.datePickerMode = UIDatePickerModeDate;
[self.datePicker addTarget:self action:@selector(datePickerValueDidChange) forControlEvents:UIControlEventValueChanged];
self.expansionView = self.datePicker;

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

- (CGFloat)expansionHeight {
// Uncomment if the picker view doesn't show on iOS 9.
// return 216;
return [super expansionHeight];
}

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

- (NSString *)dateFormat {
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;
}

- (void)datePickerValueDidChange {
self.setting.value = self.datePicker.date;
}

@end
5 changes: 4 additions & 1 deletion Bohr/BOTableViewCell+Subclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
/// The setting object which the cell represents.
@property (nonatomic) BOSetting *setting;

/// An optional view shown when the cell is pressed.
@property (nonatomic) UIView *expansionView;

/// The setup method for the cell, where you may set up all the views and constraints necessary for the cell to work.
- (void)setup;

/// The method in charge of updating the appearance of the main cell view components, through properties as mainColor, mainFont, secondaryColor, secondaryFont.
- (void)updateAppearance;

/// You may return the height for the cell to be expanded when tapped.
/// The optional height for the cell to be expanded when pressed.
- (CGFloat)expansionHeight;

/// You may return the footer text for the cell to be set on its section.
Expand Down
18 changes: 16 additions & 2 deletions Bohr/BOTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ - (instancetype)initWithTitle:(NSString *)title key:(NSString *)key handler:(voi
return self;
}

- (void)didMoveToSuperview {
if (self.superview && self.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];
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]];
}
}

- (void)setDestinationViewController:(UIViewController *)destinationViewController {
if (_destinationViewController != destinationViewController) {
_destinationViewController = destinationViewController;
Expand All @@ -45,7 +59,7 @@ + (instancetype)cellWithTitle:(NSString *)title key:(NSString *)key handler:(voi
- (void)layoutSubviews {
[super layoutSubviews];

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

self.textLabel.center = CGPointMake(self.textLabel.center.x, self.textLabel.center.y+yOffset);
Expand Down Expand Up @@ -73,7 +87,7 @@ - (void)_updateAppearance {
- (void)setup {}
- (void)setupConstraints {}
- (void)updateAppearance {}
- (CGFloat)expansionHeight {return 0;}
- (CGFloat)expansionHeight {return self.expansionView.intrinsicContentSize.height;}
- (NSString *)footerTitle {return nil;}
- (void)wasSelectedFromViewController:(BOTableViewController *)viewController {}
- (void)settingValueDidChange {}
Expand Down
41 changes: 25 additions & 16 deletions Bohr/BOTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,37 @@ @interface BOTableViewController ()

@implementation BOTableViewController

- (instancetype)init {
return [self initWithStyle:UITableViewStyleGrouped];
- (void)commonInit {
self.sections = [NSArray new];

self.tableView.estimatedRowHeight = 55;
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
self.tableView.tableFooterView = [UIView new];

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self.tableView action:@selector(endEditing:)];
tapGestureRecognizer.cancelsTouchesInView = NO;
[self.tableView addGestureRecognizer:tapGestureRecognizer];

[self setup];
}

- (instancetype)initWithStyle:(UITableViewStyle)style {
if (self = [super initWithStyle:style]) {
self.sections = [NSArray new];

self.tableView.estimatedRowHeight = 55;
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
self.tableView.tableFooterView = [UIView new];

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self.tableView action:@selector(endEditing:)];
tapGestureRecognizer.cancelsTouchesInView = NO;
[self.tableView addGestureRecognizer:tapGestureRecognizer];

[self setup];
[self commonInit];
}

return self;
}

- (instancetype)init {
return [self initWithStyle:UITableViewStyleGrouped];
}

- (void)awakeFromNib {
[self commonInit];
}

- (void)addSection:(BOTableViewSection *)section {
self.sections = [self.sections arrayByAddingObject:section];
}
Expand Down Expand Up @@ -92,7 +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 systemLayoutSizeFittingSize:CGSizeMake(cell.contentView.frame.size.width, 0)].height;
CGFloat cellHeight = [cell systemLayoutSizeFittingSize:CGSizeMake(cell.contentView.frame.size.width, UITableViewAutomaticDimension)].height;

if (cellHeight < self.tableView.estimatedRowHeight) {
cellHeight = self.tableView.estimatedRowHeight;
Expand All @@ -113,6 +121,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
BOTableViewSection *section = self.sections[indexPath.section];
BOTableViewCell *cell = section.cells[indexPath.row];
cell.indexPath = indexPath;
[cell prepareForReuse];

if (cell.setting && !cell.setting.valueDidChangeBlock) {
[UIView performWithoutAnimation:^{
Expand Down Expand Up @@ -143,7 +152,7 @@ - (void)tableView:(UITableView *)tableView willDisplayCell:(BOTableViewCell *)ce
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
BOTableViewCell *cell = (BOTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];

if (cell.expansionHeight > 0) {
if ([cell expansionHeight] > 0) {
self.expansionIndexPath = ![indexPath isEqual:self.expansionIndexPath] ? indexPath : nil;

[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
Expand Down
7 changes: 2 additions & 5 deletions Bohr/BOTimeTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
// Copyright (c) 2015 David Roman. All rights reserved.
//

#import "BOTableViewCell.h"
#import "BODateTableViewCell.h"

@interface BOTimeTableViewCell : BOTableViewCell <UIPickerViewDataSource, UIPickerViewDelegate>

/// The minute interval showed on the time picker view.
@property (nonatomic) NSInteger minuteInterval;
@interface BOTimeTableViewCell : BODateTableViewCell

@end
Loading

0 comments on commit 28b11c1

Please sign in to comment.