diff --git a/.gitignore b/.gitignore index 5897ce5..4bb236b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,17 +1,72 @@ -# Xcode + +# Created by https://www.toptal.com/developers/gitignore/api/macos,synology,xcode,swiftpackagemanager,cocoapods +# Edit at https://www.toptal.com/developers/gitignore?templates=macos,synology,xcode,swiftpackagemanager,cocoapods + +### CocoaPods ### +## CocoaPods GitIgnore Template + +# CocoaPods - Only use to conserve bandwidth / Save time on Pushing +# - Also handy if you have a large number of dependant pods +# - AS PER https://guides.cocoapods.org/using/using-cocoapods.html NEVER IGNORE THE LOCK FILE +Pods/ + +### macOS ### +# General .DS_Store -build/ -*.pbxuser -!default.pbxuser -*.mode1v3 -!default.mode1v3 -*.mode2v3 -!default.mode2v3 -*.perspectivev3 -!default.perspectivev3 -*.xccheckout +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### SwiftPackageManager ### +Packages +.build/ xcuserdata -profile -*.moved-aside -DerivedData -.idea/ +DerivedData/ +*.xcodeproj + + +### Synology ### +# Thumbnails +@eaDir +# Recycle bin +\#recycle + +### Xcode ### +## User settings +xcuserdata/ + +## Xcode 8 and earlier +*.xcscmblueprint +*.xccheckout + +### Xcode Patch ### +*.xcodeproj/* +!*.xcodeproj/project.pbxproj +!*.xcodeproj/xcshareddata/ +!*.xcworkspace/contents.xcworkspacedata +/*.gcno +**/xcshareddata/WorkspaceSettings.xcsettings + +# End of https://www.toptal.com/developers/gitignore/api/macos,synology,xcode,swiftpackagemanager,cocoapods diff --git a/CLTokenInputView/CLTokenInputView/CLBackspaceDetectingTextField.m b/CLTokenInputView/CLTokenInputView/CLBackspaceDetectingTextField.m index 9bfcb93..c713952 100644 --- a/CLTokenInputView/CLTokenInputView/CLBackspaceDetectingTextField.m +++ b/CLTokenInputView/CLTokenInputView/CLBackspaceDetectingTextField.m @@ -46,10 +46,6 @@ - (BOOL)keyboardInputShouldDelete:(UITextField *)textField { } } - if (![textField.text length] && [[[UIDevice currentDevice] systemVersion] intValue] >= 8) { - [self deleteBackward]; - } - return shouldDelete; } diff --git a/CLTokenInputView/CLTokenInputView/CLTokenInputView.m b/CLTokenInputView/CLTokenInputView/CLTokenInputView.m index 5077c14..a77fe58 100644 --- a/CLTokenInputView/CLTokenInputView/CLTokenInputView.m +++ b/CLTokenInputView/CLTokenInputView/CLTokenInputView.m @@ -274,8 +274,18 @@ - (void)repositionViews textFieldRect.size.height = STANDARD_ROW_HEIGHT; self.textField.frame = textFieldRect; + // Don't include text field in height calculation to prevent extra space from showing at the bottom + // But if we start typing in the text field then it should be included CGFloat oldContentHeight = self.intrinsicContentHeight; - self.intrinsicContentHeight = MAX(totalHeight, CGRectGetMaxY(textFieldRect)+PADDING_BOTTOM); + BOOL notFullWidth = availableWidthForTextField < bounds.size.width - PADDING_LEFT - PADDING_RIGHT - 50; + BOOL includeTextFieldHeight = notFullWidth || self.textField.text.length > 0 || self.textField.isFirstResponder; + + if (includeTextFieldHeight) { + self.intrinsicContentHeight = MAX(totalHeight, CGRectGetMaxY(textFieldRect)+PADDING_BOTTOM); + } else { + self.intrinsicContentHeight = totalHeight; + } + [self invalidateIntrinsicContentSize]; if (oldContentHeight != self.intrinsicContentHeight) { @@ -307,18 +317,13 @@ - (void)layoutSubviews - (void)textFieldDidDeleteBackwards:(UITextField *)textField { - // Delay selecting the next token slightly, so that on iOS 8 - // the deleteBackward on CLTokenView is not called immediately, - // causing a double-delete - dispatch_async(dispatch_get_main_queue(), ^{ - if (textField.text.length == 0) { - CLTokenView *tokenView = self.tokenViews.lastObject; - if (tokenView) { - [self selectTokenView:tokenView animated:YES]; - [self.textField resignFirstResponder]; - } + if (textField.text.length == 0) { + CLTokenView *tokenView = self.tokenViews.lastObject; + if (tokenView) { + [self selectTokenView:tokenView animated:YES]; + [self.textField resignFirstResponder]; } - }); + } } @@ -331,6 +336,7 @@ - (void)textFieldDidBeginEditing:(UITextField *)textField } self.tokenViews.lastObject.hideUnselectedComma = NO; [self unselectAllTokenViewsAnimated:YES]; + [self repositionViews]; } - (void)textFieldDidEndEditing:(UITextField *)textField @@ -339,6 +345,7 @@ - (void)textFieldDidEndEditing:(UITextField *)textField [self.delegate tokenInputViewDidEndEditing:self]; } self.tokenViews.lastObject.hideUnselectedComma = YES; + [self repositionViews]; } - (BOOL)textFieldShouldReturn:(UITextField *)textField @@ -368,6 +375,7 @@ - (BOOL) textField:(UITextField *)textField - (void)onTextFieldDidChange:(id)sender { + [self repositionViews]; if ([self.delegate respondsToSelector:@selector(tokenInputView:didChangeText:)]) { [self.delegate tokenInputView:self didChangeText:self.textField.text]; } diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..87d90ce --- /dev/null +++ b/Package.swift @@ -0,0 +1,20 @@ +// swift-tools-version:5.3 + +import PackageDescription + +let package = Package( + name: "CLTokenInputView", + platforms: [ + .iOS(.v11) + ], + products: [ + .library(name: "CLTokenInputView", targets: ["CLTokenInputView"]) + ], + targets: [ + .target( + name: "CLTokenInputView", + path: "CLTokenInputView/CLTokenInputView", + publicHeadersPath: "./" + ) + ] +)