Skip to content
This repository was archived by the owner on Oct 30, 2018. It is now read-only.

Implement function to setHidden for left button at TextInputBar #677

Open
wants to merge 3 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: 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
4 changes: 1 addition & 3 deletions Source/SLKTextViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,6 @@ NS_CLASS_AVAILABLE_IOS(7_0) @interface SLKTextViewController : UIViewController
/// @name Text Input Bar Adjustment
///------------------------------------------------

/** YES if the text inputbar is hidden. Default is NO. */
@property (nonatomic, getter=isTextInputbarHidden) BOOL textInputbarHidden;

/**
Changes the visibility of the text input bar.
Calling this method with the animated parameter set to NO is equivalent to setting the value of the toolbarHidden property directly.
Expand All @@ -360,6 +357,7 @@ NS_CLASS_AVAILABLE_IOS(7_0) @interface SLKTextViewController : UIViewController
*/
- (void)setTextInputbarHidden:(BOOL)hidden animated:(BOOL)animated;

- (BOOL)isTextInputBarHidden;

#pragma mark - Text Edition
///------------------------------------------------
Expand Down
14 changes: 10 additions & 4 deletions Source/SLKTextViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ @interface SLKTextViewController ()
// YES if the view controller's view's size is changing by its parent (i.e. when its window rotates or is resized)
@property (nonatomic, getter = isTransitioning) BOOL transitioning;

@property (nonatomic, readwrite) BOOL _isTextInputBarHidden;

// Optional classes to be used instead of the default ones.
@property (nonatomic, strong) Class textViewClass;
@property (nonatomic, strong) Class typingIndicatorViewClass;
Expand Down Expand Up @@ -155,7 +157,8 @@ - (void)slk_commonInit
self.keyboardPanningEnabled = YES;
self.shouldClearTextAtRightButtonPress = YES;
self.shouldScrollToBottomAfterKeyboardShows = NO;

self._isTextInputBarHidden = NO;

self.automaticallyAdjustsScrollViewInsets = YES;
self.extendedLayoutIncludesOpaqueBars = YES;
}
Expand Down Expand Up @@ -901,11 +904,12 @@ - (void)setTextInputbarHidden:(BOOL)hidden

- (void)setTextInputbarHidden:(BOOL)hidden animated:(BOOL)animated
{
if (self.isTextInputbarHidden == hidden) {
if (self._isTextInputBarHidden == hidden) {
return;
}

_textInputbar.hidden = hidden;
self._isTextInputBarHidden = hidden;

if (@available(iOS 11.0, *)) {
[self viewSafeAreaInsetsDidChange];
Expand Down Expand Up @@ -2276,7 +2280,9 @@ - (void)slk_setupViewConstraints

- (void)slk_updateViewConstraints
{
self.textInputbarHC.constant = self.textInputbar.minimumInputbarHeight;
if (!self._isTextInputBarHidden) {
self.textInputbarHC.constant = self.textInputbar.minimumInputbarHeight;
}
self.scrollViewHC.constant = [self slk_appropriateScrollViewHeight];
self.keyboardHC.constant = [self slk_appropriateKeyboardHeightFromRect:CGRectNull];

Expand Down