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

Create delegate method for changes in tokenFieldHeight #85

Merged
merged 2 commits into from
Jan 6, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Create delegate method for changes in tokenFieldHeight
  • Loading branch information
Dasmer Singh committed Dec 21, 2015
commit 6b1e78970d85ba39bb987503292c11eb0eb9f6f7
1 change: 1 addition & 0 deletions VENTokenField/VENTokenField.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)tokenField:(VENTokenField *)tokenField didDeleteTokenAtIndex:(NSUInteger)index;
- (void)tokenField:(VENTokenField *)tokenField didChangeText:(nullable NSString *)text;
- (void)tokenFieldDidBeginEditing:(VENTokenField *)tokenField;
- (void)tokenField:(VENTokenField *)tokenField didChangeContentHeight:(CGFloat)height;
@end

@protocol VENTokenFieldDataSource <NSObject>
Expand Down
14 changes: 10 additions & 4 deletions VENTokenField/VENTokenField.m
Original file line number Diff line number Diff line change
Expand Up @@ -375,19 +375,25 @@ - (UILabel *)toLabel

- (void)adjustHeightForCurrentY:(CGFloat)currentY
{
CGFloat oldHeight = self.height;
CGFloat height;
if (currentY + [self heightForToken] > CGRectGetHeight(self.frame)) { // needs to grow
if (currentY + [self heightForToken] <= self.maxHeight) {
[self setHeight:currentY + [self heightForToken] + self.verticalInset * 2];
height = currentY + [self heightForToken] + self.verticalInset * 2;
} else {
[self setHeight:self.maxHeight];
height = self.maxHeight;
}
} else { // needs to shrink
if (currentY + [self heightForToken] > self.originalHeight) {
[self setHeight:currentY + [self heightForToken] + self.verticalInset * 2];
height = currentY + [self heightForToken] + self.verticalInset * 2;
} else {
[self setHeight:self.originalHeight];
height = self.originalHeight;
}
}
if (oldHeight != height
&& [self.delegate respondsToSelector:@selector(tokenField:didChangeContentHeight:)]) {
[self.delegate tokenField:self didChangeContentHeight:height];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to also call [self setHeight:] when there is no delegate set for backwards compatibility?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

goood point

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for that catch @ayanonagon
done in a6c26aa

}

- (VENBackspaceTextField *)inputTextField
Expand Down