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

Fixed bug where screen would 'bounce' when presenting in a modal dialog ... #37

Open
wants to merge 9 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
8 changes: 4 additions & 4 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -17,6 +17,6 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
FrameAccessor: 5eec95b29b5e9a3afe72a7a2e9ed25b000d3bcc3
KIF: 2db5e8cf59136dd1267d49cca0d55883389b09d3
VENTokenField: 8b0f1fc56ac742414f65dd6a3e080cd107c3ae64
VENTokenField: 30cee52f4142abbf4c1d7134d2ffd317053306a1

COCOAPODS: 0.34.2
COCOAPODS: 0.35.0
4 changes: 2 additions & 2 deletions VENTokenField.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
13 changes: 8 additions & 5 deletions VENTokenField/VENTokenField.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@

#import <UIKit/UIKit.h>

@class VENTokenField;
@class VENTokenField, VENBackspaceTextField;
@protocol VENTokenFieldDelegate <NSObject>
@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 <NSObject>
Expand All @@ -41,13 +42,12 @@

@interface VENTokenField : UIView

@property (weak, nonatomic) id<VENTokenFieldDelegate> delegate;
@property (weak, nonatomic) id<VENTokenFieldDataSource> dataSource;
@property (weak, nonatomic) IBOutlet id<VENTokenFieldDelegate> delegate;
@property (weak, nonatomic) IBOutlet id<VENTokenFieldDataSource> dataSource;
@property (nonatomic) NSString *inputText;

- (void)reloadData;
- (void)collapse;
- (NSString *)inputText;


/**-----------------------------------------------------------------------------
* @name Customization
Expand All @@ -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;
Expand Down
48 changes: 41 additions & 7 deletions VENTokenField/VENTokenField.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ @interface VENTokenField () <VENBackspaceTextFieldDelegate>
@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;

Expand Down Expand Up @@ -80,6 +80,7 @@ - (void)setUpInit
{
// Set up default values.
_autocorrectionType = UITextAutocorrectionTypeNo;

self.maxHeight = VENTokenFieldDefaultMaxHeight;
self.verticalInset = VENTokenFieldDefaultVerticalInset;
self.horizontalInset = VENTokenFieldDefaultHorizontalInset;
Expand All @@ -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);

Expand All @@ -108,6 +109,7 @@ - (void)collapse

- (void)reloadData
{
self.inputTextField.text = nil;
[self layoutTokensAndInputWithFrameAdjustment:YES];
}

Expand Down Expand Up @@ -150,6 +152,9 @@ - (NSString *)inputText
return self.inputTextField.text;
}

-(void) setInputText:(NSString *)inputText {
self.inputTextField.text = inputText;
}

#pragma mark - View Layout

Expand Down Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for the pull-request. Instead of early return, can it be:

if (obj != self.inputTextField) {
    [obj removeFromSuperview];
}

:octocat:


[obj removeFromSuperview];
}];
self.scrollView.hidden = NO;
[self removeGestureRecognizer:self.tapGestureRecognizer];

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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]];
Expand Down Expand Up @@ -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;
Expand All @@ -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:)]) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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];
Expand Down