@@ -28,6 +28,7 @@ @interface SLKTextViewController ()
2828{
2929 CGPoint _scrollViewOffsetBeforeDragging;
3030 CGFloat _keyboardHeightBeforeDragging;
31+ CGRect _cachedKeyboardRect;
3132}
3233
3334// The shared scrollView pointer, either a tableView or collectionView
@@ -158,6 +159,8 @@ - (void)slk_commonInit
158159
159160 self.automaticallyAdjustsScrollViewInsets = YES ;
160161 self.extendedLayoutIncludesOpaqueBars = YES ;
162+
163+ _cachedKeyboardRect = CGRectNull;
161164}
162165
163166
@@ -241,7 +244,7 @@ - (void)viewSafeAreaInsetsDidChange
241244{
242245 [super viewSafeAreaInsetsDidChange ];
243246
244- [self slk_updateViewConstraints ];
247+ [self slk_updateViewConstraintsFromCachedKeyboard ];
245248}
246249
247250
@@ -396,10 +399,10 @@ - (CGFloat)slk_appropriateKeyboardHeightFromNotification:(NSNotification *)notif
396399 if ([self ignoreTextInputbarAdjustment ]) {
397400 return [self slk_appropriateBottomMargin ];
398401 }
399-
400- CGRect keyboardRect = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue ];
401-
402- return [self slk_appropriateKeyboardHeightFromRect: keyboardRect ];
402+
403+ _cachedKeyboardRect = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue ];
404+
405+ return [self slk_appropriateKeyboardHeightFromRect: _cachedKeyboardRect ];
403406}
404407
405408- (CGFloat)slk_appropriateKeyboardHeightFromRect : (CGRect)rect
@@ -588,16 +591,18 @@ - (void)setBounces:(BOOL)bounces
588591}
589592
590593- (void )slk_updateInsetAdjustmentBehavior
594+ {
591595 {
592- // Deactivate automatic scrollView adjustment for inverted table view
593- if (@ available (iOS 11.0 , *)) {
594- if (self. isInverted ) {
595- _tableView. contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
596- } else {
597- _tableView. contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
598- }
596+ {
597+ // Deactivate automatic scrollView adjustment for inverted table view
598+ if (@ available (iOS 11.0 , *) ) {
599+ if (self. isInverted ) {
600+ _tableView. contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
601+ } else {
602+ _tableView. contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
599603 }
600604 }
605+ }
601606
602607- (BOOL )slk_updateKeyboardStatus:(SLKKeyboardStatus)status
603608{
@@ -1345,7 +1350,7 @@ - (void)didPressEscapeKey:(UIKeyCommand *)keyCommand
13451350 else if (_textInputbar.isEditing ) {
13461351 [self didCancelTextEditing: keyCommand];
13471352 }
1348-
1353+
13491354 CGFloat bottomMargin = [self slk_appropriateBottomMargin ];
13501355
13511356 if ([self ignoreTextInputbarAdjustment ] || ([self .textView isFirstResponder ] && self.keyboardHC .constant == bottomMargin)) {
@@ -1399,6 +1404,8 @@ - (void)slk_willShowOrHideKeyboard:(NSNotification *)notification
13991404 // Programatically stops scrolling before updating the view constraints (to avoid scrolling glitch).
14001405 if (status == SLKKeyboardStatusWillShow) {
14011406 [self .scrollViewProxy slk_stopScrolling ];
1407+ } else if (status == SLKKeyboardStatusWillHide) {
1408+ _cachedKeyboardRect = CGRectNull;
14021409 }
14031410
14041411 // Stores the previous keyboard height
@@ -1478,6 +1485,7 @@ - (void)slk_didShowOrHideKeyboard:(NSNotification *)notification
14781485 if (!self.isViewVisible ) {
14791486 if (status == SLKKeyboardStatusDidHide && self.keyboardStatus == SLKKeyboardStatusWillHide) {
14801487 // Even if the view isn't visible anymore, let's still continue to update all states.
1488+ _cachedKeyboardRect = CGRectNull;
14811489 }
14821490 else {
14831491 return ;
@@ -2287,6 +2295,18 @@ - (void)slk_updateViewConstraints
22872295 [super updateViewConstraints ];
22882296}
22892297
2298+ - (void )slk_updateViewConstraintsFromCachedKeyboard
2299+ {
2300+ self.textInputbarHC .constant = self.textInputbar .minimumInputbarHeight ;
2301+ self.scrollViewHC .constant = [self slk_appropriateScrollViewHeight ];
2302+ self.keyboardHC .constant = [self slk_appropriateKeyboardHeightFromRect: _cachedKeyboardRect];
2303+
2304+ if (_textInputbar.isEditing ) {
2305+ self.textInputbarHC .constant += self.textInputbar .editorContentViewHeight ;
2306+ }
2307+
2308+ [super updateViewConstraints ];
2309+ }
22902310
22912311#pragma mark - Keyboard Command registration
22922312
0 commit comments