From f868b25bd5c3213956a228fe2740970c7b39204d Mon Sep 17 00:00:00 2001 From: Woudini Date: Wed, 13 May 2015 15:25:12 -0500 Subject: [PATCH 01/24] highlight and scroll to deleted tokens --- Podfile.lock | 4 ++-- VENTokenField/VENTokenField.m | 27 +++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index 4066b5e..95651b1 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -12,11 +12,11 @@ DEPENDENCIES: EXTERNAL SOURCES: VENTokenField: - :path: . + :path: "." SPEC CHECKSUMS: FrameAccessor: 0f7ba6ce37be9a5d0302a27c731dca70af8d438b KIF: ef1691e54e1d969c3b4fd0b5b56a3d7ddf37f216 VENTokenField: b944ad8c46c59fe05376d940919cb56a993db8e0 -COCOAPODS: 0.36.3 +COCOAPODS: 0.37.1 diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index 63c63a6..492f939 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -44,7 +44,8 @@ @interface VENTokenField () @property (strong, nonatomic) VENBackspaceTextField *inputTextField; @property (strong, nonatomic) UIColor *colorScheme; @property (strong, nonatomic) UILabel *collapsedLabel; - +@property (nonatomic) NSInteger indexJustBeforeDeletedToken; +@property (nonatomic) BOOL hasDeletedToken; @end @@ -227,6 +228,7 @@ - (void)layoutTokensAndInputWithFrameAdjustment:(BOOL)shouldAdjustFrame } else { [self focusInputTextField]; } + } - (BOOL)isCollapsed @@ -461,6 +463,18 @@ - (void)unhighlightAllTokens [self setCursorVisibility]; } +- (void)scrollToHighlightedToken +{ + for (VENToken *token in self.tokens) { + if (token.highlighted) + { + CGRect locationOfToken = token.frame; + [self.scrollView scrollRectToVisible:locationOfToken animated:YES]; + break; + } + } +} + - (void)setCursorVisibility { NSArray *highlightedTokens = [self.tokens filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(VENToken *evaluatedObject, NSDictionary *bindings) { @@ -473,6 +487,8 @@ - (void)setCursorVisibility } else { [self.invisibleTextField becomeFirstResponder]; } + + [self scrollToHighlightedToken]; } - (void)updateInputTextField @@ -563,7 +579,14 @@ - (void)textFieldDidEnterBackspace:(VENBackspaceTextField *)textField BOOL didDeleteToken = NO; for (VENToken *token in self.tokens) { if (token.highlighted) { - [self.delegate tokenField:self didDeleteTokenAtIndex:[self.tokens indexOfObject:token]]; + NSInteger indexOfToken = [self.tokens indexOfObject:token]; + [self.delegate tokenField:self didDeleteTokenAtIndex:indexOfToken]; + + if (indexOfToken >= 1) { + VENToken *tokenBeforeDeletedToken = self.tokens[indexOfToken-1]; + tokenBeforeDeletedToken.highlighted = YES; + } + didDeleteToken = YES; break; } From 73c603a045e8561c4b49781f07c7b4483e749248 Mon Sep 17 00:00:00 2001 From: Woudini Date: Wed, 13 May 2015 21:41:23 -0500 Subject: [PATCH 02/24] consistent deletion of consecutive items --- VENTokenField/VENTokenField.m | 46 +++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index 492f939..01c9c2d 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -26,6 +26,7 @@ #import "VENToken.h" #import "VENBackspaceTextField.h" + static const CGFloat VENTokenFieldDefaultVerticalInset = 7.0; static const CGFloat VENTokenFieldDefaultHorizontalInset = 15.0; static const CGFloat VENTokenFieldDefaultToLabelPadding = 5.0; @@ -39,13 +40,13 @@ @interface VENTokenField () @property (strong, nonatomic) UIScrollView *scrollView; @property (strong, nonatomic) NSMutableArray *tokens; @property (assign, nonatomic) CGFloat originalHeight; +@property (nonatomic) CGFloat oldHeight; @property (strong, nonatomic) UITapGestureRecognizer *tapGestureRecognizer; @property (strong, nonatomic) VENBackspaceTextField *invisibleTextField; @property (strong, nonatomic) VENBackspaceTextField *inputTextField; @property (strong, nonatomic) UIColor *colorScheme; @property (strong, nonatomic) UILabel *collapsedLabel; -@property (nonatomic) NSInteger indexJustBeforeDeletedToken; -@property (nonatomic) BOOL hasDeletedToken; +@property (nonatomic) NSInteger indexOfTokenPriorToDeletedToken; @end @@ -101,12 +102,18 @@ - (void)setUpInit _toLabelText = NSLocalizedString(@"To:", nil); self.originalHeight = CGRectGetHeight(self.frame); + self.oldHeight = self.originalHeight; // Add invisible text field to handle backspace when we don't have a real first responder. [self layoutInvisibleTextField]; [self layoutScrollView]; [self reloadData]; + + [[NSNotificationCenter defaultCenter] addObserverForName:@"VENDidShrinkFrameNotification" object:self queue:nil usingBlock:^(NSNotification *note) { + VENToken *tokenToHighlight = self.tokens[self.indexOfTokenPriorToDeletedToken]; + tokenToHighlight.highlighted = YES; + }]; } - (void)collapse @@ -174,6 +181,7 @@ - (NSString *)inputText - (void)layoutSubviews { + CGFloat newHeight = self.bounds.size.height; [super layoutSubviews]; self.scrollView.contentSize = CGSizeMake(CGRectGetWidth(self.frame) - self.horizontalInset * 2, CGRectGetHeight(self.frame) - self.verticalInset * 2); if ([self isCollapsed]) { @@ -181,6 +189,12 @@ - (void)layoutSubviews } else { [self layoutTokensAndInputWithFrameAdjustment:NO]; } + + if (newHeight < self.oldHeight) + { + [[NSNotificationCenter defaultCenter] postNotificationName:@"VENDidShrinkFrameNotification" object:self]; + } + self.oldHeight = self.bounds.size.height; } - (void)layoutCollapsedLabel @@ -383,8 +397,10 @@ - (void)adjustHeightForCurrentY:(CGFloat)currentY } } else { // needs to shrink if (currentY + [self heightForToken] > self.originalHeight) { + // This is called no matter whether the frame height is being reduced or not when deleting tokens [self setHeight:currentY + [self heightForToken] + self.verticalInset * 2]; } else { + // This is called only when the frame is being reduced to its original height [self setHeight:self.originalHeight]; } } @@ -459,22 +475,9 @@ - (void)unhighlightAllTokens for (VENToken *token in self.tokens) { token.highlighted = NO; } - [self setCursorVisibility]; } -- (void)scrollToHighlightedToken -{ - for (VENToken *token in self.tokens) { - if (token.highlighted) - { - CGRect locationOfToken = token.frame; - [self.scrollView scrollRectToVisible:locationOfToken animated:YES]; - break; - } - } -} - - (void)setCursorVisibility { NSArray *highlightedTokens = [self.tokens filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(VENToken *evaluatedObject, NSDictionary *bindings) { @@ -486,9 +489,14 @@ - (void)setCursorVisibility [self inputTextFieldBecomeFirstResponder]; } else { [self.invisibleTextField becomeFirstResponder]; + + // Scroll to highlighted token + + VENToken *tokenOfInterest = [highlightedTokens firstObject]; + CGRect locationOfToken = tokenOfInterest.frame; + [self.scrollView scrollRectToVisible:locationOfToken animated:YES]; } - - [self scrollToHighlightedToken]; + } - (void)updateInputTextField @@ -582,8 +590,10 @@ - (void)textFieldDidEnterBackspace:(VENBackspaceTextField *)textField NSInteger indexOfToken = [self.tokens indexOfObject:token]; [self.delegate tokenField:self didDeleteTokenAtIndex:indexOfToken]; + // Highlight the token prior to the token deleted if (indexOfToken >= 1) { - VENToken *tokenBeforeDeletedToken = self.tokens[indexOfToken-1]; + self.indexOfTokenPriorToDeletedToken = indexOfToken-1; + VENToken *tokenBeforeDeletedToken = self.tokens[self.indexOfTokenPriorToDeletedToken]; tokenBeforeDeletedToken.highlighted = YES; } From 98c0e9a951ee0c760087612950f443c32ab6f089 Mon Sep 17 00:00:00 2001 From: Woudini Date: Wed, 13 May 2015 21:46:57 -0500 Subject: [PATCH 03/24] remove observer in dealloc --- VENTokenField/VENTokenField.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index 01c9c2d..00db04a 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -179,6 +179,10 @@ - (NSString *)inputText #pragma mark - View Layout +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self forKeyPath:@"VENDidShrinkFrameNotification"]; +} + - (void)layoutSubviews { CGFloat newHeight = self.bounds.size.height; From 204f1d24cd0dc3ed237aaa06d50309eecbf0b3bd Mon Sep 17 00:00:00 2001 From: Woudini Date: Wed, 13 May 2015 21:52:07 -0500 Subject: [PATCH 04/24] add define strings for shrinking notification --- VENTokenField/VENTokenField.m | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index 00db04a..e887a1a 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -26,6 +26,7 @@ #import "VENToken.h" #import "VENBackspaceTextField.h" +#define VENDidShrinkBoundsHeightNotification @"VENDidShrinkBoundsHeightNotification" static const CGFloat VENTokenFieldDefaultVerticalInset = 7.0; static const CGFloat VENTokenFieldDefaultHorizontalInset = 15.0; @@ -110,7 +111,7 @@ - (void)setUpInit [self layoutScrollView]; [self reloadData]; - [[NSNotificationCenter defaultCenter] addObserverForName:@"VENDidShrinkFrameNotification" object:self queue:nil usingBlock:^(NSNotification *note) { + [[NSNotificationCenter defaultCenter] addObserverForName:VENDidShrinkBoundsHeightNotification object:self queue:nil usingBlock:^(NSNotification *note) { VENToken *tokenToHighlight = self.tokens[self.indexOfTokenPriorToDeletedToken]; tokenToHighlight.highlighted = YES; }]; @@ -180,7 +181,7 @@ - (NSString *)inputText #pragma mark - View Layout - (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self forKeyPath:@"VENDidShrinkFrameNotification"]; + [[NSNotificationCenter defaultCenter] removeObserver:self forKeyPath:VENDidShrinkBoundsHeightNotification]; } - (void)layoutSubviews @@ -196,7 +197,7 @@ - (void)layoutSubviews if (newHeight < self.oldHeight) { - [[NSNotificationCenter defaultCenter] postNotificationName:@"VENDidShrinkFrameNotification" object:self]; + [[NSNotificationCenter defaultCenter] postNotificationName:VENDidShrinkBoundsHeightNotification object:self]; } self.oldHeight = self.bounds.size.height; } From b417256ad5a9c00bc85bf329ae5d03f273b96502 Mon Sep 17 00:00:00 2001 From: Woudini Date: Wed, 13 May 2015 22:12:35 -0500 Subject: [PATCH 05/24] maintain cursor when deleting from end --- VENTokenField/VENTokenField.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index e887a1a..8fff127 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -596,7 +596,7 @@ - (void)textFieldDidEnterBackspace:(VENBackspaceTextField *)textField [self.delegate tokenField:self didDeleteTokenAtIndex:indexOfToken]; // Highlight the token prior to the token deleted - if (indexOfToken >= 1) { + if (indexOfToken >= 1 && indexOfToken < self.tokens.count-1) { self.indexOfTokenPriorToDeletedToken = indexOfToken-1; VENToken *tokenBeforeDeletedToken = self.tokens[self.indexOfTokenPriorToDeletedToken]; tokenBeforeDeletedToken.highlighted = YES; From 442d47c2aa6d0a37567fa2bdceff3d616434fe21 Mon Sep 17 00:00:00 2001 From: Woudini Date: Wed, 13 May 2015 22:26:58 -0500 Subject: [PATCH 06/24] document changes in more detail --- VENTokenField.xcodeproj/project.pbxproj | 2 ++ VENTokenField/VENTokenField.m | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/VENTokenField.xcodeproj/project.pbxproj b/VENTokenField.xcodeproj/project.pbxproj index 1931315..be64ce9 100644 --- a/VENTokenField.xcodeproj/project.pbxproj +++ b/VENTokenField.xcodeproj/project.pbxproj @@ -440,6 +440,7 @@ CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = ""; COPY_PHASE_STRIP = NO; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; @@ -479,6 +480,7 @@ CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = ""; COPY_PHASE_STRIP = YES; ENABLE_NS_ASSERTIONS = NO; GCC_C_LANGUAGE_STANDARD = gnu99; diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index 8fff127..895f581 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -111,6 +111,8 @@ - (void)setUpInit [self layoutScrollView]; [self reloadData]; + // When deleting items in the middle of the list rather than at the end, the highlighted token is lost when the view shrinks, so observe for when the view shrinks and highlight the appropriate token + [[NSNotificationCenter defaultCenter] addObserverForName:VENDidShrinkBoundsHeightNotification object:self queue:nil usingBlock:^(NSNotification *note) { VENToken *tokenToHighlight = self.tokens[self.indexOfTokenPriorToDeletedToken]; tokenToHighlight.highlighted = YES; @@ -495,7 +497,7 @@ - (void)setCursorVisibility } else { [self.invisibleTextField becomeFirstResponder]; - // Scroll to highlighted token + // Scroll to highlighted token - beware that the scrollView is jumpy VENToken *tokenOfInterest = [highlightedTokens firstObject]; CGRect locationOfToken = tokenOfInterest.frame; @@ -595,7 +597,7 @@ - (void)textFieldDidEnterBackspace:(VENBackspaceTextField *)textField NSInteger indexOfToken = [self.tokens indexOfObject:token]; [self.delegate tokenField:self didDeleteTokenAtIndex:indexOfToken]; - // Highlight the token prior to the token deleted + // Highlight the token prior to the token deleted, only if we are deleting from the middle of the list if (indexOfToken >= 1 && indexOfToken < self.tokens.count-1) { self.indexOfTokenPriorToDeletedToken = indexOfToken-1; VENToken *tokenBeforeDeletedToken = self.tokens[self.indexOfTokenPriorToDeletedToken]; From fcd84f966c9ea2b47be47d3ae5dc5232a37197d6 Mon Sep 17 00:00:00 2001 From: Woudini Date: Wed, 13 May 2015 22:54:34 -0500 Subject: [PATCH 07/24] use this commit if you only want contiguous deletion feature --- VENTokenField/VENTokenField.m | 6 ------ 1 file changed, 6 deletions(-) diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index 895f581..ad6f855 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -496,12 +496,6 @@ - (void)setCursorVisibility [self inputTextFieldBecomeFirstResponder]; } else { [self.invisibleTextField becomeFirstResponder]; - - // Scroll to highlighted token - beware that the scrollView is jumpy - - VENToken *tokenOfInterest = [highlightedTokens firstObject]; - CGRect locationOfToken = tokenOfInterest.frame; - [self.scrollView scrollRectToVisible:locationOfToken animated:YES]; } } From 646b5c7e44df581f2a12dbd0e79ad7ecd4c4f6a0 Mon Sep 17 00:00:00 2001 From: Woudini Date: Wed, 13 May 2015 23:13:36 -0500 Subject: [PATCH 08/24] use this commit for both contiguous deletion and scrolling to highlighted token --- VENTokenField/VENTokenField.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index ad6f855..895f581 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -496,6 +496,12 @@ - (void)setCursorVisibility [self inputTextFieldBecomeFirstResponder]; } else { [self.invisibleTextField becomeFirstResponder]; + + // Scroll to highlighted token - beware that the scrollView is jumpy + + VENToken *tokenOfInterest = [highlightedTokens firstObject]; + CGRect locationOfToken = tokenOfInterest.frame; + [self.scrollView scrollRectToVisible:locationOfToken animated:YES]; } } From ea05c1a3b2ae9e6f7a675d2be056e6afd45b613b Mon Sep 17 00:00:00 2001 From: Woudini Date: Wed, 13 May 2015 23:57:28 -0500 Subject: [PATCH 09/24] remove unnecessary notification --- VENTokenField/VENTokenField.m | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index 895f581..b5399da 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -26,8 +26,6 @@ #import "VENToken.h" #import "VENBackspaceTextField.h" -#define VENDidShrinkBoundsHeightNotification @"VENDidShrinkBoundsHeightNotification" - static const CGFloat VENTokenFieldDefaultVerticalInset = 7.0; static const CGFloat VENTokenFieldDefaultHorizontalInset = 15.0; static const CGFloat VENTokenFieldDefaultToLabelPadding = 5.0; @@ -112,11 +110,6 @@ - (void)setUpInit [self reloadData]; // When deleting items in the middle of the list rather than at the end, the highlighted token is lost when the view shrinks, so observe for when the view shrinks and highlight the appropriate token - - [[NSNotificationCenter defaultCenter] addObserverForName:VENDidShrinkBoundsHeightNotification object:self queue:nil usingBlock:^(NSNotification *note) { - VENToken *tokenToHighlight = self.tokens[self.indexOfTokenPriorToDeletedToken]; - tokenToHighlight.highlighted = YES; - }]; } - (void)collapse @@ -182,10 +175,6 @@ - (NSString *)inputText #pragma mark - View Layout -- (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self forKeyPath:VENDidShrinkBoundsHeightNotification]; -} - - (void)layoutSubviews { CGFloat newHeight = self.bounds.size.height; @@ -199,7 +188,8 @@ - (void)layoutSubviews if (newHeight < self.oldHeight) { - [[NSNotificationCenter defaultCenter] postNotificationName:VENDidShrinkBoundsHeightNotification object:self]; + VENToken *tokenToHighlight = self.tokens[self.indexOfTokenPriorToDeletedToken]; + tokenToHighlight.highlighted = YES; } self.oldHeight = self.bounds.size.height; } From 4eccea38c4f881ea3404b9d541fc4452f7a5ce1b Mon Sep 17 00:00:00 2001 From: Woudini Date: Thu, 14 May 2015 00:16:04 -0500 Subject: [PATCH 10/24] maintain normal deletion behavior at the end of the list --- VENTokenField/VENTokenField.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index b5399da..16ae21a 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -186,7 +186,7 @@ - (void)layoutSubviews [self layoutTokensAndInputWithFrameAdjustment:NO]; } - if (newHeight < self.oldHeight) + if (newHeight < self.oldHeight && self.indexOfTokenPriorToDeletedToken != 0) { VENToken *tokenToHighlight = self.tokens[self.indexOfTokenPriorToDeletedToken]; tokenToHighlight.highlighted = YES; From 22529270943ff1ee60693bccafd2ff29c0ddcba5 Mon Sep 17 00:00:00 2001 From: Woudini Date: Thu, 14 May 2015 00:19:32 -0500 Subject: [PATCH 11/24] use this newer commit for contiguous deletion in middle of list only --- VENTokenField/VENTokenField.m | 7 ------- 1 file changed, 7 deletions(-) diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index 16ae21a..1809ce9 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -486,14 +486,7 @@ - (void)setCursorVisibility [self inputTextFieldBecomeFirstResponder]; } else { [self.invisibleTextField becomeFirstResponder]; - - // Scroll to highlighted token - beware that the scrollView is jumpy - - VENToken *tokenOfInterest = [highlightedTokens firstObject]; - CGRect locationOfToken = tokenOfInterest.frame; - [self.scrollView scrollRectToVisible:locationOfToken animated:YES]; } - } - (void)updateInputTextField From 488ba66b93cc816ec0a340b2a674bd14160f519f Mon Sep 17 00:00:00 2001 From: Woudini Date: Thu, 14 May 2015 00:20:11 -0500 Subject: [PATCH 12/24] use this newer commit for contiguous deletion in middle of list and scrolling to highlighted token --- VENTokenField/VENTokenField.m | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index 1809ce9..16ae21a 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -486,7 +486,14 @@ - (void)setCursorVisibility [self inputTextFieldBecomeFirstResponder]; } else { [self.invisibleTextField becomeFirstResponder]; + + // Scroll to highlighted token - beware that the scrollView is jumpy + + VENToken *tokenOfInterest = [highlightedTokens firstObject]; + CGRect locationOfToken = tokenOfInterest.frame; + [self.scrollView scrollRectToVisible:locationOfToken animated:YES]; } + } - (void)updateInputTextField From f150cc5aae3e816027f004358fabcf3a9bee9651 Mon Sep 17 00:00:00 2001 From: Woudini Date: Thu, 14 May 2015 00:27:29 -0500 Subject: [PATCH 13/24] separate features into methods --- VENTokenField/VENTokenField.m | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index 16ae21a..b03fcc1 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -188,12 +188,17 @@ - (void)layoutSubviews if (newHeight < self.oldHeight && self.indexOfTokenPriorToDeletedToken != 0) { - VENToken *tokenToHighlight = self.tokens[self.indexOfTokenPriorToDeletedToken]; - tokenToHighlight.highlighted = YES; + [self continueHighlightingTokensDuringDeletionInMiddleOfListWhenHeightIsReduced]; } self.oldHeight = self.bounds.size.height; } +- (void)continueHighlightingTokensDuringDeletionInMiddleOfListWhenHeightIsReduced +{ + VENToken *tokenToHighlight = self.tokens[self.indexOfTokenPriorToDeletedToken]; + tokenToHighlight.highlighted = YES; +} + - (void)layoutCollapsedLabel { [self.collapsedLabel removeFromSuperview]; @@ -486,14 +491,16 @@ - (void)setCursorVisibility [self inputTextFieldBecomeFirstResponder]; } else { [self.invisibleTextField becomeFirstResponder]; - - // Scroll to highlighted token - beware that the scrollView is jumpy - - VENToken *tokenOfInterest = [highlightedTokens firstObject]; - CGRect locationOfToken = tokenOfInterest.frame; - [self.scrollView scrollRectToVisible:locationOfToken animated:YES]; + [self scrollToHighlightedToken:[highlightedTokens firstObject]]; } +} +- (void)scrollToHighlightedToken:(VENToken *)token +{ + // Scroll to highlighted token - beware that the scrollView is jumpy + VENToken *tokenOfInterest = token; + CGRect locationOfToken = tokenOfInterest.frame; + [self.scrollView scrollRectToVisible:locationOfToken animated:YES]; } - (void)updateInputTextField From d0e5c99d82e48d691739d87d1fd1789a49a9adf7 Mon Sep 17 00:00:00 2001 From: Woudini Date: Thu, 14 May 2015 00:39:39 -0500 Subject: [PATCH 14/24] fix if conditions that were preventing the prior token index from being updated --- VENTokenField/VENTokenField.m | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index b03fcc1..9efbe50 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -186,7 +186,7 @@ - (void)layoutSubviews [self layoutTokensAndInputWithFrameAdjustment:NO]; } - if (newHeight < self.oldHeight && self.indexOfTokenPriorToDeletedToken != 0) + if (newHeight < self.oldHeight) { [self continueHighlightingTokensDuringDeletionInMiddleOfListWhenHeightIsReduced]; } @@ -593,12 +593,15 @@ - (void)textFieldDidEnterBackspace:(VENBackspaceTextField *)textField if (token.highlighted) { NSInteger indexOfToken = [self.tokens indexOfObject:token]; [self.delegate tokenField:self didDeleteTokenAtIndex:indexOfToken]; - // Highlight the token prior to the token deleted, only if we are deleting from the middle of the list - if (indexOfToken >= 1 && indexOfToken < self.tokens.count-1) { + if (indexOfToken >= 1) { self.indexOfTokenPriorToDeletedToken = indexOfToken-1; - VENToken *tokenBeforeDeletedToken = self.tokens[self.indexOfTokenPriorToDeletedToken]; - tokenBeforeDeletedToken.highlighted = YES; + NSLog(@"indexofprior is %tu", self.indexOfTokenPriorToDeletedToken); + + if (indexOfToken < self.tokens.count-1) { + VENToken *tokenBeforeDeletedToken = self.tokens[self.indexOfTokenPriorToDeletedToken]; + tokenBeforeDeletedToken.highlighted = YES; + } } didDeleteToken = YES; From 2cce85910480c37a61f978b4235abd41554f732d Mon Sep 17 00:00:00 2001 From: Woudini Date: Thu, 14 May 2015 00:47:27 -0500 Subject: [PATCH 15/24] fix missing highlighted token when second to last token selected --- VENTokenField/VENTokenField.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index 9efbe50..49f6e4a 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -598,7 +598,7 @@ - (void)textFieldDidEnterBackspace:(VENBackspaceTextField *)textField self.indexOfTokenPriorToDeletedToken = indexOfToken-1; NSLog(@"indexofprior is %tu", self.indexOfTokenPriorToDeletedToken); - if (indexOfToken < self.tokens.count-1) { + if (indexOfToken < self.tokens.count) { VENToken *tokenBeforeDeletedToken = self.tokens[self.indexOfTokenPriorToDeletedToken]; tokenBeforeDeletedToken.highlighted = YES; } From 1ac36d321c6577282dc53acb0dcc53e86e6f397a Mon Sep 17 00:00:00 2001 From: Woudini Date: Thu, 14 May 2015 00:53:11 -0500 Subject: [PATCH 16/24] need to anticipate middle deletions for longer lists, will attempt tomorrow --- VENTokenField/VENTokenField.m | 1 - 1 file changed, 1 deletion(-) diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index 49f6e4a..24db993 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -596,7 +596,6 @@ - (void)textFieldDidEnterBackspace:(VENBackspaceTextField *)textField // Highlight the token prior to the token deleted, only if we are deleting from the middle of the list if (indexOfToken >= 1) { self.indexOfTokenPriorToDeletedToken = indexOfToken-1; - NSLog(@"indexofprior is %tu", self.indexOfTokenPriorToDeletedToken); if (indexOfToken < self.tokens.count) { VENToken *tokenBeforeDeletedToken = self.tokens[self.indexOfTokenPriorToDeletedToken]; From c1fd9e4fa6a9b4bdfd28b69494dd63f68acad51b Mon Sep 17 00:00:00 2001 From: Woudini Date: Thu, 14 May 2015 09:45:49 -0500 Subject: [PATCH 17/24] prevent indexoftokenpriortodeletedtoken from being set to less than zero --- VENTokenField/VENTokenField.m | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index 24db993..1c58f2b 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -594,13 +594,12 @@ - (void)textFieldDidEnterBackspace:(VENBackspaceTextField *)textField NSInteger indexOfToken = [self.tokens indexOfObject:token]; [self.delegate tokenField:self didDeleteTokenAtIndex:indexOfToken]; // Highlight the token prior to the token deleted, only if we are deleting from the middle of the list - if (indexOfToken >= 1) { - self.indexOfTokenPriorToDeletedToken = indexOfToken-1; - - if (indexOfToken < self.tokens.count) { - VENToken *tokenBeforeDeletedToken = self.tokens[self.indexOfTokenPriorToDeletedToken]; - tokenBeforeDeletedToken.highlighted = YES; - } + + self.indexOfTokenPriorToDeletedToken = indexOfToken > 0 ? indexOfToken-1 : 0; + + if (indexOfToken < self.tokens.count) { + VENToken *tokenBeforeDeletedToken = self.tokens[self.indexOfTokenPriorToDeletedToken]; + tokenBeforeDeletedToken.highlighted = YES; } didDeleteToken = YES; From a3c754e760362acbf00d495d23c04fbd73af56d7 Mon Sep 17 00:00:00 2001 From: Woudini Date: Thu, 14 May 2015 10:19:27 -0500 Subject: [PATCH 18/24] prevent continued highlighting from occuring when adding tokens --- VENTokenField/VENTokenField.h | 2 ++ VENTokenField/VENTokenField.m | 5 ++--- VENTokenFieldSample/ViewController.m | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/VENTokenField/VENTokenField.h b/VENTokenField/VENTokenField.h index 73ea5dd..f3645c4 100644 --- a/VENTokenField/VENTokenField.h +++ b/VENTokenField/VENTokenField.h @@ -74,6 +74,8 @@ @property (copy, nonatomic) NSString *placeholderText; @property (copy, nonatomic) NSString *inputTextFieldAccessibilityLabel; +@property (nonatomic) BOOL isDeletingTokens; + - (void)setColorScheme:(UIColor *)color; @end diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index 1c58f2b..8a867fd 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -108,8 +108,7 @@ - (void)setUpInit [self layoutScrollView]; [self reloadData]; - - // When deleting items in the middle of the list rather than at the end, the highlighted token is lost when the view shrinks, so observe for when the view shrinks and highlight the appropriate token + } - (void)collapse @@ -186,7 +185,7 @@ - (void)layoutSubviews [self layoutTokensAndInputWithFrameAdjustment:NO]; } - if (newHeight < self.oldHeight) + if (newHeight < self.oldHeight && self.isDeletingTokens) { [self continueHighlightingTokensDuringDeletionInMiddleOfListWhenHeightIsReduced]; } diff --git a/VENTokenFieldSample/ViewController.m b/VENTokenFieldSample/ViewController.m index 073f85f..e4a9a2e 100644 --- a/VENTokenFieldSample/ViewController.m +++ b/VENTokenFieldSample/ViewController.m @@ -43,12 +43,14 @@ - (IBAction)didTapResignFirstResponderButton:(id)sender - (void)tokenField:(VENTokenField *)tokenField didEnterText:(NSString *)text { + self.tokenField.isDeletingTokens = NO; [self.names addObject:text]; [self.tokenField reloadData]; } - (void)tokenField:(VENTokenField *)tokenField didDeleteTokenAtIndex:(NSUInteger)index { + self.tokenField.isDeletingTokens = YES; [self.names removeObjectAtIndex:index]; [self.tokenField reloadData]; } From e05e10dc5bed08a4bfa880bd9273957c49d79e84 Mon Sep 17 00:00:00 2001 From: Woudini Date: Thu, 14 May 2015 10:40:51 -0500 Subject: [PATCH 19/24] use contentSize instead of bounds for detecting height changes to cover all instances --- VENTokenField/VENTokenField.m | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index 8a867fd..94151d6 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -176,7 +176,7 @@ - (NSString *)inputText - (void)layoutSubviews { - CGFloat newHeight = self.bounds.size.height; + CGFloat newHeight = self.scrollView.contentSize.height; [super layoutSubviews]; self.scrollView.contentSize = CGSizeMake(CGRectGetWidth(self.frame) - self.horizontalInset * 2, CGRectGetHeight(self.frame) - self.verticalInset * 2); if ([self isCollapsed]) { @@ -184,12 +184,11 @@ - (void)layoutSubviews } else { [self layoutTokensAndInputWithFrameAdjustment:NO]; } - - if (newHeight < self.oldHeight && self.isDeletingTokens) + if (newHeight < self.oldHeight && self.isDeletingTokens ) { [self continueHighlightingTokensDuringDeletionInMiddleOfListWhenHeightIsReduced]; } - self.oldHeight = self.bounds.size.height; + self.oldHeight = self.scrollView.contentSize.height; } - (void)continueHighlightingTokensDuringDeletionInMiddleOfListWhenHeightIsReduced From f337b716b54c046f89b1d917e42841751c7d1982 Mon Sep 17 00:00:00 2001 From: Woudini Date: Thu, 14 May 2015 11:14:33 -0500 Subject: [PATCH 20/24] focusInputTextField only when adding items --- VENTokenField/VENTokenField.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index 94151d6..854c593 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -242,7 +242,6 @@ - (void)layoutTokensAndInputWithFrameAdjustment:(BOOL)shouldAdjustFrame } else { [self focusInputTextField]; } - } - (BOOL)isCollapsed @@ -510,7 +509,8 @@ - (void)focusInputTextField { CGPoint contentOffset = self.scrollView.contentOffset; CGFloat targetY = self.inputTextField.y + [self heightForToken] - self.maxHeight; - if (targetY > contentOffset.y) { + + if (targetY > contentOffset.y && !self.isDeletingTokens) { [self.scrollView setContentOffset:CGPointMake(contentOffset.x, targetY) animated:NO]; } } From 4eca9876da59426ec984b4dc322269966790c303 Mon Sep 17 00:00:00 2001 From: Woudini Date: Thu, 14 May 2015 13:34:13 -0500 Subject: [PATCH 21/24] focus on textfield when typing --- VENTokenField/VENTokenField.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index 854c593..e5690e9 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -577,6 +577,8 @@ - (void)textFieldDidBeginEditing:(UITextField *)textField - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { [self unhighlightAllTokens]; + self.isDeletingTokens = NO; + [self focusInputTextField]; return YES; } From 0220f1631318695f16ab6b17e154056c8cefca1f Mon Sep 17 00:00:00 2001 From: woudini Date: Fri, 15 May 2015 08:02:38 -0500 Subject: [PATCH 22/24] revert changes to original --- Podfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index 95651b1..4066b5e 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -12,11 +12,11 @@ DEPENDENCIES: EXTERNAL SOURCES: VENTokenField: - :path: "." + :path: . SPEC CHECKSUMS: FrameAccessor: 0f7ba6ce37be9a5d0302a27c731dca70af8d438b KIF: ef1691e54e1d969c3b4fd0b5b56a3d7ddf37f216 VENTokenField: b944ad8c46c59fe05376d940919cb56a993db8e0 -COCOAPODS: 0.37.1 +COCOAPODS: 0.36.3 From c0d4cac5dd9a857eb96fb13626d56646d3f31d4e Mon Sep 17 00:00:00 2001 From: woudini Date: Fri, 15 May 2015 08:03:46 -0500 Subject: [PATCH 23/24] revert pbxproj to original --- VENTokenField.xcodeproj/project.pbxproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/VENTokenField.xcodeproj/project.pbxproj b/VENTokenField.xcodeproj/project.pbxproj index be64ce9..1931315 100644 --- a/VENTokenField.xcodeproj/project.pbxproj +++ b/VENTokenField.xcodeproj/project.pbxproj @@ -440,7 +440,6 @@ CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = ""; COPY_PHASE_STRIP = NO; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; @@ -480,7 +479,6 @@ CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = ""; COPY_PHASE_STRIP = YES; ENABLE_NS_ASSERTIONS = NO; GCC_C_LANGUAGE_STANDARD = gnu99; From c5c068df2d9478bd54590b9fe8d06e32d5208df8 Mon Sep 17 00:00:00 2001 From: woudini Date: Fri, 15 May 2015 09:20:51 -0500 Subject: [PATCH 24/24] remove dated comment --- VENTokenField/VENTokenField.m | 1 - 1 file changed, 1 deletion(-) diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index e5690e9..d7b916f 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -494,7 +494,6 @@ - (void)setCursorVisibility - (void)scrollToHighlightedToken:(VENToken *)token { - // Scroll to highlighted token - beware that the scrollView is jumpy VENToken *tokenOfInterest = token; CGRect locationOfToken = tokenOfInterest.frame; [self.scrollView scrollRectToVisible:locationOfToken animated:YES];