Skip to content

Implement function to setHidden for left button at TextInputBar #1

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

Merged
merged 1 commit into from
Jul 25, 2018
Merged
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: 8 additions & 0 deletions Source/SLKTextInputbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ NS_ASSUME_NONNULL_BEGIN
/** The right action button action. */
@property (nonatomic, strong) UIButton *rightButton;

/** YES if the right button should be hidden animatedly in case the text view has no text in it. Default is YES. */
@property (nonatomic, readwrite) BOOL leftButtonIsHidden;

/** YES if the right button should be hidden animatedly in case the text view has no text in it. Default is YES. */
@property (nonatomic, readwrite) BOOL autoHideRightButton;

Expand Down Expand Up @@ -119,6 +122,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)endTextEdition;

/**
Set hidden state for left button.
*/
- (void)setLeftButtonHidden:(BOOL)isHidden;


#pragma mark - Text Counting
///------------------------------------------------
Expand Down
17 changes: 15 additions & 2 deletions Source/SLKTextInputbar.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ - (void)slk_commonInit
self.charCountLabelWarningColor = [UIColor redColor];

self.autoHideRightButton = YES;
self.leftButtonIsHidden = YES;
self.editorContentViewHeight = 38.0;
self.contentInset = UIEdgeInsetsMake(5.0, 8.0, 5.0, 8.0);

Expand Down Expand Up @@ -517,6 +518,13 @@ - (void)setCounterPosition:(SLKCounterPosition)counterPosition
[self addConstraints:self.charCountLabelVCs];
}

- (void)setLeftButtonHidden:(BOOL)isHidden
{
self.leftButtonIsHidden = isHidden;
CGFloat leftButtonWidth = isHidden ? 0 : [self.rightButton intrinsicContentSize].width;
self.leftButton.hidden = isHidden;
self.leftButtonWC.constant = leftButtonWidth;
}

#pragma mark - Text Editing

Expand Down Expand Up @@ -713,8 +721,13 @@ - (void)slk_updateConstraintConstants
self.leftButtonBottomMarginC.constant = roundf((self.intrinsicContentSize.height - leftButtonSize.height) / 2.0) + self.slk_contentViewHeight / 2.0;
}

self.leftButtonWC.constant = roundf(leftButtonSize.width);
self.leftMarginWC.constant = (leftButtonSize.width > 0) ? self.contentInset.left : zero;
if (self.leftButtonIsHidden) {
self.leftButtonWC.constant = 0;
self.leftMarginWC.constant = zero;
} else {
self.leftButtonWC.constant = roundf(leftButtonSize.width);
self.leftMarginWC.constant = (leftButtonSize.width > 0) ? self.contentInset.left : zero;
}

self.rightButtonWC.constant = [self slk_appropriateRightButtonWidth];
self.rightMarginWC.constant = [self slk_appropriateRightButtonMargin];
Expand Down