diff --git a/SlackTextViewController.podspec b/SlackTextViewController.podspec index 9eb8d4d5..705930a2 100644 --- a/SlackTextViewController.podspec +++ b/SlackTextViewController.podspec @@ -1,4 +1,4 @@ -@version = "1.9.8-bw" +@version = "1.9.9-bw" Pod::Spec.new do |s| s.name = "SlackTextViewController" diff --git a/SlackTextViewController/SlackTextViewController/Info.plist b/SlackTextViewController/SlackTextViewController/Info.plist index 6ce6f3e3..691c23b3 100644 --- a/SlackTextViewController/SlackTextViewController/Info.plist +++ b/SlackTextViewController/SlackTextViewController/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.9.8-bw + 1.9.9-bw CFBundleSignature ???? CFBundleVersion diff --git a/Source/SLKTextViewController.m b/Source/SLKTextViewController.m index ab4c77d5..ef8d8c9f 100644 --- a/Source/SLKTextViewController.m +++ b/Source/SLKTextViewController.m @@ -28,6 +28,7 @@ @interface SLKTextViewController () { CGPoint _scrollViewOffsetBeforeDragging; CGFloat _keyboardHeightBeforeDragging; + CGRect _cachedKeyboardRect; } // The shared scrollView pointer, either a tableView or collectionView @@ -158,6 +159,8 @@ - (void)slk_commonInit self.automaticallyAdjustsScrollViewInsets = YES; self.extendedLayoutIncludesOpaqueBars = YES; + + _cachedKeyboardRect = CGRectNull; } @@ -241,7 +244,7 @@ - (void)viewSafeAreaInsetsDidChange { [super viewSafeAreaInsetsDidChange]; - [self slk_updateViewConstraints]; + [self slk_updateViewConstraintsFromCachedKeyboard]; } @@ -396,10 +399,10 @@ - (CGFloat)slk_appropriateKeyboardHeightFromNotification:(NSNotification *)notif if ([self ignoreTextInputbarAdjustment]) { return [self slk_appropriateBottomMargin]; } - - CGRect keyboardRect = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; - - return [self slk_appropriateKeyboardHeightFromRect:keyboardRect]; + + _cachedKeyboardRect = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue]; + + return [self slk_appropriateKeyboardHeightFromRect:_cachedKeyboardRect]; } - (CGFloat)slk_appropriateKeyboardHeightFromRect:(CGRect)rect @@ -588,16 +591,18 @@ - (void)setBounces:(BOOL)bounces } - (void)slk_updateInsetAdjustmentBehavior +{ { - // Deactivate automatic scrollView adjustment for inverted table view - if (@available(iOS 11.0, *)) { - if (self.isInverted) { - _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; - } else { - _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic; - } +{ + // Deactivate automatic scrollView adjustment for inverted table view + if (@available(iOS 11.0, *)) { + if (self.isInverted) { + _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; + } else { + _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic; } } +} - (BOOL)slk_updateKeyboardStatus:(SLKKeyboardStatus)status { @@ -1345,7 +1350,7 @@ - (void)didPressEscapeKey:(UIKeyCommand *)keyCommand else if (_textInputbar.isEditing) { [self didCancelTextEditing:keyCommand]; } - + CGFloat bottomMargin = [self slk_appropriateBottomMargin]; if ([self ignoreTextInputbarAdjustment] || ([self.textView isFirstResponder] && self.keyboardHC.constant == bottomMargin)) { @@ -1399,6 +1404,8 @@ - (void)slk_willShowOrHideKeyboard:(NSNotification *)notification // Programatically stops scrolling before updating the view constraints (to avoid scrolling glitch). if (status == SLKKeyboardStatusWillShow) { [self.scrollViewProxy slk_stopScrolling]; + } else if (status == SLKKeyboardStatusWillHide) { + _cachedKeyboardRect = CGRectNull; } // Stores the previous keyboard height @@ -1478,6 +1485,7 @@ - (void)slk_didShowOrHideKeyboard:(NSNotification *)notification if (!self.isViewVisible) { if (status == SLKKeyboardStatusDidHide && self.keyboardStatus == SLKKeyboardStatusWillHide) { // Even if the view isn't visible anymore, let's still continue to update all states. + _cachedKeyboardRect = CGRectNull; } else { return; @@ -2287,6 +2295,18 @@ - (void)slk_updateViewConstraints [super updateViewConstraints]; } +- (void)slk_updateViewConstraintsFromCachedKeyboard +{ + self.textInputbarHC.constant = self.textInputbar.minimumInputbarHeight; + self.scrollViewHC.constant = [self slk_appropriateScrollViewHeight]; + self.keyboardHC.constant = [self slk_appropriateKeyboardHeightFromRect:_cachedKeyboardRect]; + + if (_textInputbar.isEditing) { + self.textInputbarHC.constant += self.textInputbar.editorContentViewHeight; + } + + [super updateViewConstraints]; +} #pragma mark - Keyboard Command registration