1 Commits

Author SHA1 Message Date
Borba 8171cf11b5 change formDescriptorCellHeightForRowDescriptor class method to instance method
add DynamicTextView cell type
2015-03-19 15:27:32 -03:00
10 changed files with 73 additions and 12 deletions
@@ -110,6 +110,14 @@ NSString *const kNotes = @"notes";
row = [XLFormRowDescriptor formRowDescriptorWithTag:kNotes rowType:XLFormRowDescriptorTypeTextView title:@"Notes"];
[section addFormRow:row];
section = [XLFormSectionDescriptor formSectionWithTitle:@"Dynamic Text View"];
[formDescriptor addFormSection:section];
row = [XLFormRowDescriptor formRowDescriptorWithTag:kTextView rowType:XLFormRowDescriptorTypeDynamicTextView];
[row.cellConfigAtConfigure setObject:@"DYNAMIC TEXT VIEW EXAMPLE" forKey:@"textView.placeholder"];
[row.cellConfigAtConfigure setObject:@(50) forKey:@"defaultHeight"];
[section addFormRow:row];
return [super initWithForm:formDescriptor];
}
+1 -1
View File
@@ -62,7 +62,7 @@
}
+(CGFloat)formDescriptorCellHeightForRowDescriptor:(XLFormRowDescriptor *)rowDescriptor
-(CGFloat)formDescriptorCellHeightForRowDescriptor:(XLFormRowDescriptor *)rowDescriptor
{
return 216.0f;
}
+2 -1
View File
@@ -39,7 +39,8 @@
@optional
+(CGFloat)formDescriptorCellHeightForRowDescriptor:(XLFormRowDescriptor *)rowDescriptor;
+(CGFloat)formDescriptorCellHeightForRowDescriptor:(XLFormRowDescriptor *)rowDescriptor DEPRECATED_ATTRIBUTE DEPRECATED_MSG_ATTRIBUTE("use instance method formDescriptorCellHeightForRowDescriptor: instead");
-(CGFloat)formDescriptorCellHeightForRowDescriptor:(XLFormRowDescriptor *)rowDescriptor;
-(BOOL)formDescriptorCellCanBecomeFirstResponder;
-(BOOL)formDescriptorCellBecomeFirstResponder;
-(void)formDescriptorCellDidSelectedWithFormController:(XLFormViewController *)controller;
+1 -1
View File
@@ -85,7 +85,7 @@
}
+(CGFloat)formDescriptorCellHeightForRowDescriptor:(XLFormRowDescriptor *)rowDescriptor
-(CGFloat)formDescriptorCellHeightForRowDescriptor:(XLFormRowDescriptor *)rowDescriptor
{
return 216.0f;
}
+1 -1
View File
@@ -77,7 +77,7 @@
self.rowDescriptor.value = @(self.slider.value);
}
+(CGFloat)formDescriptorCellHeightForRowDescriptor:(XLFormRowDescriptor *)rowDescriptor {
-(CGFloat)formDescriptorCellHeightForRowDescriptor:(XLFormRowDescriptor *)rowDescriptor {
return 88;
}
+1
View File
@@ -32,5 +32,6 @@
@property (nonatomic, readonly) UILabel * label DEPRECATED_ATTRIBUTE DEPRECATED_MSG_ATTRIBUTE("Use textLabel instead");
@property (nonatomic, readonly) UILabel * textLabel;
@property (nonatomic, readonly) XLFormTextView * textView;
@property (nonatomic) NSNumber * defaultHeight;
@end
+49 -5
View File
@@ -28,11 +28,16 @@
#import "XLFormViewController.h"
#import "XLFormTextView.h"
#import "XLFormTextViewCell.h"
#import "XLForm.h"
NSString *const kFormTextViewCellPlaceholder = @"placeholder";
static const CGFloat kPaddingLeft = 16;
static const CGFloat kPaddingRight = 16;
static const CGFloat kKeyboardSpace = 10;
@interface XLFormTextViewCell() <UITextViewDelegate>
@property (nonatomic) UITextView * dummyTextView;
@end
@implementation XLFormTextViewCell
@@ -42,6 +47,7 @@ NSString *const kFormTextViewCellPlaceholder = @"placeholder";
@synthesize textLabel = _textLabel;
@synthesize textView = _textView;
@synthesize dummyTextView = _dummyTextView;
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
@@ -89,6 +95,13 @@ NSString *const kFormTextViewCellPlaceholder = @"placeholder";
return _textView;
}
-(UITextView *)dummyTextView
{
if (_dummyTextView) return _dummyTextView;
_dummyTextView = [[UITextView alloc] init];
return _dummyTextView;
}
#pragma mark - XLFormDescriptorCell
-(void)configure
@@ -117,12 +130,27 @@ NSString *const kFormTextViewCellPlaceholder = @"placeholder";
[self.textView setEditable:!self.rowDescriptor.disabled];
self.textView.textColor = self.rowDescriptor.disabled ? [UIColor grayColor] : [UIColor blackColor];
self.textLabel.textColor = self.rowDescriptor.disabled ? [UIColor grayColor] : [UIColor blackColor];
self.textLabel.text = ((self.rowDescriptor.required && self.rowDescriptor.title && self.rowDescriptor.sectionDescriptor.formDescriptor.addAsteriskToRequiredRowsTitle) ? [NSString stringWithFormat:@"%@*", self.rowDescriptor.title]: self.rowDescriptor.title);
self.textView.scrollEnabled = [self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeTextView];
if ([self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeTextView]){
self.textLabel.text = ((self.rowDescriptor.required && self.rowDescriptor.title && self.rowDescriptor.sectionDescriptor.formDescriptor.addAsteriskToRequiredRowsTitle) ? [NSString stringWithFormat:@"%@*", self.rowDescriptor.title]: self.rowDescriptor.title);
}
}
+(CGFloat)formDescriptorCellHeightForRowDescriptor:(XLFormRowDescriptor *)rowDescriptor
-(CGFloat)formDescriptorCellHeightForRowDescriptor:(XLFormRowDescriptor *)rowDescriptor
{
return 110.f;
if ([rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeTextView]){
return ([self.defaultHeight floatValue]) ?: 110.f;
}
// Configure the dummy text view
self.dummyTextView.font = self.textView.font;
self.dummyTextView.text = rowDescriptor.value ?: @" ";
CGSize textViewSize = [self.dummyTextView sizeThatFits:CGSizeMake(self.contentView.frame.size.width - kPaddingLeft - kPaddingRight, FLT_MAX)];
CGFloat height = ceilf(textViewSize.height) + 1; // 1 is for contentView height diference on cell
return MAX(height, [self.defaultHeight floatValue]);
}
-(BOOL)formDescriptorCellCanBecomeFirstResponder
@@ -157,7 +185,9 @@ NSString *const kFormTextViewCellPlaceholder = @"placeholder";
}
NSDictionary * views = @{@"label": self.textLabel, @"textView": self.textView};
if (!self.textLabel.text || [self.textLabel.text isEqualToString:@""]){
[_dynamicCustomConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-16-[textView]-16-|" options:0 metrics:0 views:views]];
NSDictionary *metrics = @{@"paddingLeft":[NSNumber numberWithFloat:kPaddingLeft],
@"paddingRight":[NSNumber numberWithFloat:kPaddingRight]};
[_dynamicCustomConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(paddingLeft)-[textView]-(paddingRight)-|" options:0 metrics:metrics views:views]];
}
else{
[_dynamicCustomConstraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-16-[label]-[textView]-4-|" options:0 metrics:0 views:views]];
@@ -196,6 +226,20 @@ NSString *const kFormTextViewCellPlaceholder = @"placeholder";
} else {
self.rowDescriptor.value = nil;
}
if ([self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeDynamicTextView]){
// Update height
UITableView * tableView = self.formViewController.tableView;
[UIView setAnimationsEnabled:NO];
[tableView beginUpdates];
[tableView endUpdates];
[UIView setAnimationsEnabled:YES];
// Scroll
CGRect cursorRect = [self.textView caretRectForPosition:self.textView.selectedTextRange.end];
CGRect newRect = CGRectMake(cursorRect.origin.x, cursorRect.origin.y + kKeyboardSpace, cursorRect.size.width, cursorRect.size.height);
[tableView scrollRectToVisible:[tableView convertRect:newRect fromView:self.textView] animated:NO];
}
}
@end
+8 -3
View File
@@ -202,6 +202,7 @@
XLFormRowDescriptorTypeMultipleSelector: [XLFormSelectorCell class],
XLFormRowDescriptorTypeMultipleSelectorPopover: [XLFormSelectorCell class],
XLFormRowDescriptorTypeTextView: [XLFormTextViewCell class],
XLFormRowDescriptorTypeDynamicTextView: [XLFormTextViewCell class],
XLFormRowDescriptorTypeButton: [XLFormButtonCell class],
XLFormRowDescriptorTypeInfo: [XLFormSelectorCell class],
XLFormRowDescriptorTypeBooleanSwitch : [XLFormSwitchCell class],
@@ -505,9 +506,13 @@
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
XLFormRowDescriptor *rowDescriptor = [self.form formRowAtIndex:indexPath];
Class cellClass = [[rowDescriptor cellForFormController:self] class];
if ([cellClass respondsToSelector:@selector(formDescriptorCellHeightForRowDescriptor:)]){
return [cellClass formDescriptorCellHeightForRowDescriptor:rowDescriptor];
id<XLFormDescriptorCell> cell = [rowDescriptor cellForFormController:self];
if ([cell respondsToSelector:@selector(formDescriptorCellHeightForRowDescriptor:)]){
return [cell formDescriptorCellHeightForRowDescriptor:rowDescriptor];
}
else if ([[cell class] respondsToSelector:@selector(formDescriptorCellHeightForRowDescriptor:)]){
return [[cell class] formDescriptorCellHeightForRowDescriptor:rowDescriptor];
}
return self.tableView.rowHeight;
}
+1
View File
@@ -79,6 +79,7 @@ extern NSString *const XLFormRowDescriptorTypeAccount;
extern NSString *const XLFormRowDescriptorTypeInteger;
extern NSString *const XLFormRowDescriptorTypeDecimal;
extern NSString *const XLFormRowDescriptorTypeTextView;
extern NSString *const XLFormRowDescriptorTypeDynamicTextView;
extern NSString *const XLFormRowDescriptorTypeSelectorPush;
extern NSString *const XLFormRowDescriptorTypeSelectorPopover;
extern NSString *const XLFormRowDescriptorTypeSelectorActionSheet;
+1
View File
@@ -38,6 +38,7 @@ NSString *const XLFormRowDescriptorTypeAccount = @"account";
NSString *const XLFormRowDescriptorTypeInteger = @"integer";
NSString *const XLFormRowDescriptorTypeDecimal = @"decimal";
NSString *const XLFormRowDescriptorTypeTextView = @"textView";
NSString *const XLFormRowDescriptorTypeDynamicTextView = @"dynamicTextView";
NSString *const XLFormRowDescriptorTypeSelectorPush = @"selectorPush";
NSString *const XLFormRowDescriptorTypeSelectorPopover = @"selectorPopover";
NSString *const XLFormRowDescriptorTypeSelectorActionSheet = @"selectorActionSheet";