Skip to content

Commit

Permalink
Clear input when we are adjusting frame
Browse files Browse the repository at this point in the history
This resolves issue venmo#76
When we are laying out subviews, we were already passing NO for adjustFrame.
When we are reloading data, we were already passing YES for adjustFrame.

It turns out that when we are not adjustingFrame, we do not want to clear the user-entered text, so reuse this boolean to keep from clearing the user text.
  • Loading branch information
Raymond Walsh committed Aug 27, 2015
1 parent a9d058c commit 3387a21
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions VENTokenField/VENTokenField.m
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ - (void)layoutTokensAndInputWithFrameAdjustment:(BOOL)shouldAdjustFrame

[self layoutToLabelInView:self.scrollView origin:CGPointZero currentX:&currentX];
[self layoutTokensWithCurrentX:&currentX currentY:&currentY];
[self layoutInputTextFieldWithCurrentX:&currentX currentY:&currentY];
[self layoutInputTextFieldWithCurrentX:&currentX currentY:&currentY clearInput:shouldAdjustFrame];

if (shouldAdjustFrame) {
[self adjustHeightForCurrentY:currentY];
Expand Down Expand Up @@ -248,7 +248,7 @@ - (void)layoutScrollView
[self addSubview:self.scrollView];
}

- (void)layoutInputTextFieldWithCurrentX:(CGFloat *)currentX currentY:(CGFloat *)currentY
- (void)layoutInputTextFieldWithCurrentX:(CGFloat *)currentX currentY:(CGFloat *)currentY clearInput:(BOOL)clearInput
{
CGFloat inputTextFieldWidth = self.scrollView.contentSize.width - *currentX;
if (inputTextFieldWidth < self.minInputWidth) {
Expand All @@ -258,7 +258,9 @@ - (void)layoutInputTextFieldWithCurrentX:(CGFloat *)currentX currentY:(CGFloat *
}

VENBackspaceTextField *inputTextField = self.inputTextField;
inputTextField.text = @"";
if (clearInput) {
inputTextField.text = @"";
}
inputTextField.frame = CGRectMake(*currentX, *currentY + 1, inputTextFieldWidth, [self heightForToken] - 1);
inputTextField.tintColor = self.colorScheme;
[self.scrollView addSubview:inputTextField];
Expand Down

0 comments on commit 3387a21

Please sign in to comment.