diff --git a/Podfile.lock b/Podfile.lock index f845f8f..35a5d16 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,9 +1,9 @@ PODS: - FrameAccessor (1.3.2) - KIF (3.0.8): - - KIF/XCTest + - KIF/XCTest (= 3.0.8) - KIF/XCTest (3.0.8) - - VENTokenField (2.2.3): + - VENTokenField (3.0): - FrameAccessor (~> 1.0) DEPENDENCIES: @@ -17,6 +17,6 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: FrameAccessor: 5eec95b29b5e9a3afe72a7a2e9ed25b000d3bcc3 KIF: 2db5e8cf59136dd1267d49cca0d55883389b09d3 - VENTokenField: 8b0f1fc56ac742414f65dd6a3e080cd107c3ae64 + VENTokenField: 30cee52f4142abbf4c1d7134d2ffd317053306a1 -COCOAPODS: 0.34.2 +COCOAPODS: 0.35.0 diff --git a/VENTokenField.podspec b/VENTokenField.podspec index 96e415f..f680bd4 100644 --- a/VENTokenField.podspec +++ b/VENTokenField.podspec @@ -5,11 +5,11 @@ Pod::Spec.new do |s| s.description = <<-DESC An easy to use token field that in used in the Venmo app. DESC - s.homepage = 'https://github.com/venmo/VENTokenField' + s.homepage = 'https://github.com/rrossinvicara/VENTokenField' s.screenshot = 'http://i.imgur.com/a1FfEBi.gif' s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { 'Venmo' => 'ios@venmo.com'} - s.source = { :git => 'https://github.com/venmo/VENTokenField.git', :tag => "v#{s.version}" } + s.source = { :git => 'https://github.com/rrossinvicara/VENTokenField.git', :tag => "v#{s.version}" } s.source_files = 'VENTokenField/**/*.{h,m}' s.resources = ["VENTokenField/**/*.{xib,png}"] s.dependency 'FrameAccessor', '~> 1.0' diff --git a/VENTokenField/VENTokenField.h b/VENTokenField/VENTokenField.h index 657174e..fe557f4 100644 --- a/VENTokenField/VENTokenField.h +++ b/VENTokenField/VENTokenField.h @@ -22,13 +22,14 @@ #import -@class VENTokenField; +@class VENTokenField, VENBackspaceTextField; @protocol VENTokenFieldDelegate @optional - (void)tokenField:(VENTokenField *)tokenField didEnterText:(NSString *)text; - (void)tokenField:(VENTokenField *)tokenField didDeleteTokenAtIndex:(NSUInteger)index; - (void)tokenField:(VENTokenField *)tokenField didChangeText:(NSString *)text; - (void)tokenFieldDidBeginEditing:(VENTokenField *)tokenField; +- (void)tokenFieldDidEndEditing:(VENTokenField *) tokenField; @end @protocol VENTokenFieldDataSource @@ -41,13 +42,12 @@ @interface VENTokenField : UIView -@property (weak, nonatomic) id delegate; -@property (weak, nonatomic) id dataSource; +@property (weak, nonatomic) IBOutlet id delegate; +@property (weak, nonatomic) IBOutlet id dataSource; +@property (nonatomic) NSString *inputText; - (void)reloadData; - (void)collapse; -- (NSString *)inputText; - /**----------------------------------------------------------------------------- * @name Customization @@ -61,11 +61,14 @@ @property (assign, nonatomic) CGFloat minInputWidth; @property (assign, nonatomic) UIKeyboardType inputTextFieldKeyboardType; +@property (assign, nonatomic) UIReturnKeyType inputTextFieldReturnKeyType; @property (assign, nonatomic) UITextAutocorrectionType autocorrectionType; @property (strong, nonatomic) UIColor *toLabelTextColor; @property (strong, nonatomic) NSString *toLabelText; @property (strong, nonatomic) UIColor *inputTextFieldTextColor; +@property (strong, nonatomic) VENBackspaceTextField *inputTextField; + @property (strong, nonatomic) UILabel *toLabel; @property (copy, nonatomic) NSString *placeholderText; diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index 3c8597c..f89122c 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -41,7 +41,7 @@ @interface VENTokenField () @property (assign, nonatomic) CGFloat originalHeight; @property (strong, nonatomic) UITapGestureRecognizer *tapGestureRecognizer; @property (strong, nonatomic) VENBackspaceTextField *invisibleTextField; -@property (strong, nonatomic) VENBackspaceTextField *inputTextField; +// @property (strong, nonatomic) VENBackspaceTextField *inputTextField; @property (strong, nonatomic) UIColor *colorScheme; @property (strong, nonatomic) UILabel *collapsedLabel; @@ -80,6 +80,7 @@ - (void)setUpInit { // Set up default values. _autocorrectionType = UITextAutocorrectionTypeNo; + self.maxHeight = VENTokenFieldDefaultMaxHeight; self.verticalInset = VENTokenFieldDefaultVerticalInset; self.horizontalInset = VENTokenFieldDefaultHorizontalInset; @@ -88,7 +89,7 @@ - (void)setUpInit self.colorScheme = [UIColor blueColor]; self.toLabelTextColor = [UIColor colorWithRed:112/255.0f green:124/255.0f blue:124/255.0f alpha:1.0f]; self.inputTextFieldTextColor = [UIColor colorWithRed:38/255.0f green:39/255.0f blue:41/255.0f alpha:1.0f]; - + self.inputTextFieldReturnKeyType = UIReturnKeyDefault; // Accessing bare value to avoid kicking off a premature layout run. _toLabelText = NSLocalizedString(@"To:", nil); @@ -108,6 +109,7 @@ - (void)collapse - (void)reloadData { + self.inputTextField.text = nil; [self layoutTokensAndInputWithFrameAdjustment:YES]; } @@ -150,6 +152,9 @@ - (NSString *)inputText return self.inputTextField.text; } +-(void) setInputText:(NSString *)inputText { + self.inputTextField.text = inputText; +} #pragma mark - View Layout @@ -183,7 +188,11 @@ - (void)layoutTokensAndInputWithFrameAdjustment:(BOOL)shouldAdjustFrame { [self.collapsedLabel removeFromSuperview]; BOOL inputFieldShouldBecomeFirstResponder = self.inputTextField.isFirstResponder; - [self.scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; + [self.scrollView.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + if (obj == self.inputTextField) return; + + [obj removeFromSuperview]; + }]; self.scrollView.hidden = NO; [self removeGestureRecognizer:self.tapGestureRecognizer]; @@ -240,7 +249,7 @@ - (void)layoutInputTextFieldWithCurrentX:(CGFloat *)currentX currentY:(CGFloat * } VENBackspaceTextField *inputTextField = self.inputTextField; - inputTextField.text = @""; + // inputTextField.text = @""; inputTextField.frame = CGRectMake(*currentX, *currentY + 1, inputTextFieldWidth, [self heightForToken] - 1); inputTextField.tintColor = self.colorScheme; [self.scrollView addSubview:inputTextField]; @@ -283,8 +292,9 @@ - (void)layoutTokensWithCurrentX:(CGFloat *)currentX currentY:(CGFloat *)current token.colorScheme = self.colorScheme; __weak VENToken *weakToken = token; + __weak VENTokenField *weakSelf = self; token.didTapTokenBlock = ^{ - [self didTapToken:weakToken]; + [weakSelf didTapToken:weakToken]; }; [token setTitleText:[NSString stringWithFormat:@"%@,", title]]; @@ -379,6 +389,9 @@ - (VENBackspaceTextField *)inputTextField _inputTextField.tintColor = self.colorScheme; _inputTextField.delegate = self; _inputTextField.placeholder = self.placeholderText; + _inputTextField.clearsOnBeginEditing = NO; + _inputTextField.returnKeyType = self.inputTextFieldReturnKeyType; + [_inputTextField addTarget:self action:@selector(inputTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; } return _inputTextField; @@ -396,6 +409,14 @@ - (void)setInputTextFieldKeyboardType:(UIKeyboardType)inputTextFieldKeyboardType [self.inputTextField setKeyboardType:self.inputTextFieldKeyboardType]; } + +-(void) setInputTextFieldReturnKeyType:(UIReturnKeyType)inputTextFieldReturnKeyType { + _inputTextFieldReturnKeyType = inputTextFieldReturnKeyType; + + [self.inputTextField setReturnKeyType:inputTextFieldReturnKeyType]; + [self.invisibleTextField setReturnKeyType:inputTextFieldReturnKeyType]; +} + - (void)inputTextFieldDidChange:(UITextField *)textField { if ([self.delegate respondsToSelector:@selector(tokenField:didChangeText:)]) { @@ -488,9 +509,9 @@ - (NSString *)collapsedText - (BOOL)textFieldShouldReturn:(UITextField *)textField { if ([self.delegate respondsToSelector:@selector(tokenField:didEnterText:)]) { - if ([textField.text length]) { + // if ([textField.text length]) { [self.delegate tokenField:self didEnterText:textField.text]; - } + // } } return NO; } @@ -499,9 +520,22 @@ - (void)textFieldDidBeginEditing:(UITextField *)textField { if (textField == self.inputTextField) { [self unhighlightAllTokens]; + + if ([self.delegate respondsToSelector:@selector(tokenFieldDidBeginEditing:)]) { + [self.delegate tokenFieldDidBeginEditing:self]; + } } } +-(void) textFieldDidEndEditing:(UITextField *)textField { + dispatch_async(dispatch_get_main_queue(), ^{ + if (!([self.inputTextField isFirstResponder] || [self.invisibleTextField isFirstResponder])) { + if ([self.delegate respondsToSelector:@selector(tokenFieldDidEndEditing:)]) { + [self.delegate tokenFieldDidEndEditing:self]; + } + } + }); +} - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { [self unhighlightAllTokens];