Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
brandFromNSK committed Apr 20, 2018
1 parent 734447a commit 362b97c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
23 changes: 11 additions & 12 deletions Classes/MVVM/Elements/IDEntryField/View/IDEntryFieldCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ @interface IDEntryFieldCell () <UITextFieldDelegate, UITextViewDelegate>
@property (strong, nonatomic) NSArray <UIView *> *bottomSeparators;
@property (strong, nonatomic) UILabel *bottomLabel;

@property (strong, nonatomic) NSString *uniqueIdentifier;

@end

@implementation IDEntryFieldCell
Expand Down Expand Up @@ -62,10 +60,6 @@ - (void)layoutSubviews {
- (void)installViewModel:(IDEntryFieldCellViewModel *)viewModel {
[super installViewModel:viewModel];

if (![self.uniqueIdentifier isEqualToString:viewModel.uniqueIdentifier]) {
self.uniqueIdentifier = viewModel.uniqueIdentifier;
}

self.secondaryViewModelInstalling = _viewModel ? YES : NO;
self.viewModelUpdated = YES;
}
Expand Down Expand Up @@ -125,10 +119,7 @@ - (void)bindEntryModels {
#pragma mark - Private
- (void)updateViewIfNeeded {

if (self.uniqueIdentifier != nil && self.viewModel.uniqueIdentifier != nil) {
NSAssert([self.uniqueIdentifier isEqualToString:self.viewModel.uniqueIdentifier], @"Why is different? May be cell reused wrong?");
}

NSAssert(self.viewModel.fieldModels.count == self.entryFields.count, @"Why is different? May be cell reused wrong?");

if (_viewModel && self.viewModelUpdated) {

Expand All @@ -140,7 +131,11 @@ - (void)updateViewIfNeeded {
entryField.placeholder = fieldModel.placeholder;
entryField.editable = fieldModel.editable;
entryField.showFloatingLabel = fieldModel.showFloatingLabel;
entryField.keyboardType = fieldModel.numericKeyboard ? UIKeyboardTypeASCIICapableNumberPad : UIKeyboardTypeDefault;
if (@available(iOS 10.0, *)) {
entryField.keyboardType = fieldModel.numericKeyboard ? UIKeyboardTypeASCIICapableNumberPad : UIKeyboardTypeDefault;
} else {
entryField.keyboardType = fieldModel.numericKeyboard ? UIKeyboardTypePhonePad : UIKeyboardTypeDefault;
}

NSTextAlignment alignment = [self.viewModel textAlignmentWithPosition:self.viewModel.position];
entryField.textAlignment = alignment;
Expand Down Expand Up @@ -443,7 +438,11 @@ - (void)handleTextReplacementInEntryField: (UIView <IDEntryFieldProtocol> *)entr
}
else { // With pattern

entryField.keyboardType = UIKeyboardTypeASCIICapableNumberPad;
if (@available(iOS 10.0, *)) {
entryField.keyboardType = UIKeyboardTypeASCIICapableNumberPad;
} else {
entryField.keyboardType = UIKeyboardTypePhonePad;
}

if ([self.viewModel singleDeleteForPatternedFieldWithText:previousValue range:range]) {
changedString = [self.viewModel changedStringWithPatternHandling:changedString range:range];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
+ (instancetype)viewModelWithFieldModels: (NSArray <IDEntryFieldCellFieldModel *> *)fieldModels;
+ (instancetype)viewModelWithValue: (NSString *)value keyPath: (NSString *)keyPath;

@property (strong, nonatomic) NSString *uniqueIdentifier;

@property (weak, nonatomic) id <IDEntryFieldCellViewModelDelegate> delegate;
@property (strong, nonatomic, readonly) NSArray <IDEntryFieldCellFieldModel *> *fieldModels;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

@interface IDEntryFieldCellViewModel ()

@property (strong, nonatomic, readwrite) NSString *uniqueIdentifier;

@property (strong, nonatomic, readwrite) RACSignal *valueSignal;
@property (strong, nonatomic, readwrite) NSArray <IDEntryFieldCellFieldModel *> *fieldModels;
@property (strong, nonatomic) NSString *descriptionText;
Expand All @@ -20,22 +22,20 @@ @interface IDEntryFieldCellViewModel ()
@implementation IDEntryFieldCellViewModel

- (NSString *)cellIdentifier {
return @"IDEntryFieldCell";
return [NSString stringWithFormat:@"IDEntryFieldCell**%lu**%lu**",
(unsigned long)_fieldModels.count,
(unsigned long)_fieldModels.firstObject.entryFieldType];
}

+ (instancetype)viewModelWithFieldModel: (IDEntryFieldCellFieldModel *)fieldModel {
return [self viewModelWithFieldModels:@[fieldModel]];
}

+ (instancetype)viewModelWithFieldModels: (NSArray <IDEntryFieldCellFieldModel *> *)fieldModels {

if (self == [IDEntryFieldCellViewModel class]) {

IDEntryFieldCellViewModel *viewModel = [[IDEntryFieldCellViewModel alloc] init];
viewModel.fieldModels = fieldModels;
return viewModel;
}
return nil;

IDEntryFieldCellViewModel *viewModel = [[IDEntryFieldCellViewModel alloc] init];
viewModel.fieldModels = fieldModels;
return viewModel;
}

+ (instancetype)viewModelWithValue: (NSString *)value keyPath: (NSString *)keyPath {
Expand Down Expand Up @@ -70,6 +70,7 @@ - (void)setFieldModels:(NSArray<IDEntryFieldCellFieldModel *> *)fieldModels {
static CGFloat const kDefaultRightInset = 20.0f;
- (void)initializeDefaultProperties {

_uniqueIdentifier = [[NSUUID UUID] UUIDString];
_backgroundColor = [UIColor clearColor];
_contentInsets = UIEdgeInsetsMake(0, kDefaultLeftInset, 0, kDefaultRightInset);
_manualValidation = NO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ - (void)registerReusableCellWithCellViewModels:(NSArray<id<IDCellViewModelProtoc

for( NSString *reusableIdentifier in identifiers ) {

Class cellClass = objc_getClass([reusableIdentifier cStringUsingEncoding:NSUTF8StringEncoding]);
NSArray *reusedStringArray = [reusableIdentifier componentsSeparatedByString:@"**"];
Class cellClass = objc_getClass([reusedStringArray.firstObject cStringUsingEncoding:NSUTF8StringEncoding]);
NSAssert(Nil != cellClass, @"Class for cell '%@' should be named exactly as ReusableID", reusableIdentifier);

NSBundle *bundle = [NSBundle bundleForClass:cellClass];
Expand Down
2 changes: 1 addition & 1 deletion IDTableModuleCore.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'IDTableModuleCore'
s.version = '0.0.12'
s.version = '0.0.13'
s.summary = 'IDTableModuleCore created for easy module configuration based on UITableView'

# This description is used to generate tags and improve search results.
Expand Down

0 comments on commit 362b97c

Please sign in to comment.