Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where tapping backspace to delete a single letter also selects the previous token #43

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 70 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ - (BOOL)keyboardInputShouldDelete:(UITextField *)textField {
}
}

if (![textField.text length] && [[[UIDevice currentDevice] systemVersion] intValue] >= 8) {
[self deleteBackward];
}

return shouldDelete;
}

Expand Down
32 changes: 20 additions & 12 deletions CLTokenInputView/CLTokenInputView/CLTokenInputView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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];
}
});
}
}


Expand All @@ -331,6 +336,7 @@ - (void)textFieldDidBeginEditing:(UITextField *)textField
}
self.tokenViews.lastObject.hideUnselectedComma = NO;
[self unselectAllTokenViewsAnimated:YES];
[self repositionViews];
}

- (void)textFieldDidEndEditing:(UITextField *)textField
Expand All @@ -339,6 +345,7 @@ - (void)textFieldDidEndEditing:(UITextField *)textField
[self.delegate tokenInputViewDidEndEditing:self];
}
self.tokenViews.lastObject.hideUnselectedComma = YES;
[self repositionViews];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
Expand Down Expand Up @@ -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];
}
Expand Down
20 changes: 20 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -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: "./"
)
]
)