diff --git a/Source/SLKTextInputbar.h b/Source/SLKTextInputbar.h index 2ca5e0f6..a2c3c287 100644 --- a/Source/SLKTextInputbar.h +++ b/Source/SLKTextInputbar.h @@ -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; @@ -119,6 +122,11 @@ NS_ASSUME_NONNULL_BEGIN */ - (void)endTextEdition; +/** + Set hidden state for left button. + */ +- (void)setLeftButtonHidden:(BOOL)isHidden; + #pragma mark - Text Counting ///------------------------------------------------ diff --git a/Source/SLKTextInputbar.m b/Source/SLKTextInputbar.m index ca970691..b1dd0586 100644 --- a/Source/SLKTextInputbar.m +++ b/Source/SLKTextInputbar.m @@ -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); @@ -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 @@ -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]; diff --git a/Source/SLKTextViewController.h b/Source/SLKTextViewController.h index aa66d0af..9da3ed83 100644 --- a/Source/SLKTextViewController.h +++ b/Source/SLKTextViewController.h @@ -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. @@ -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 ///------------------------------------------------ diff --git a/Source/SLKTextViewController.m b/Source/SLKTextViewController.m index 60a3fc18..8148b55f 100644 --- a/Source/SLKTextViewController.m +++ b/Source/SLKTextViewController.m @@ -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; @@ -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; } @@ -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]; @@ -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];