From 04fba1cd32197d50c3d83c47f294b32aacc60303 Mon Sep 17 00:00:00 2001 From: pro100Andrey Date: Wed, 2 May 2018 16:15:40 +0300 Subject: [PATCH] fixed GitHub issue 149 - When Keyboard is visible, swipe back gesture causes UI to run infinite loop of layout updates. App becomes unresponsible. Issue appears ONLY when keyboard is VISIBLE. Disabling interactive pop gesture recogniser of navigation controller solves this problem. --- QMChatViewController/QMChatViewController.m | 55 +++++++++------------ 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/QMChatViewController/QMChatViewController.m b/QMChatViewController/QMChatViewController.m index f6b72bf..f56080f 100644 --- a/QMChatViewController/QMChatViewController.m +++ b/QMChatViewController/QMChatViewController.m @@ -93,21 +93,20 @@ - (void)viewDidLoad { self.systemInputToolbar.frame = CGRectMake(0, 0, 0, kQMSystemInputToolbarDebugHeight); self.systemInputToolbar.hostViewFrameChangeBlock = ^(UIView *view, BOOL animated) { - CGFloat pos = weakSelf.view.frame.size.height - [view.superview convertPoint:view.frame.origin toView:weakSelf.view].y; - + CGFloat pos = weakSelf.view.frame.size.height - [weakSelf.view.superview convertPoint:view.frame.origin toView:weakSelf.view].y; + if (weakSelf.inputToolbar.contentView.textView.isFirstResponder) { - - if (view.superview.frame.origin.y > 0 && pos == 0) { + if (view.superview.frame.origin.y > 0 && pos <= 0) { return; } } - + const CGFloat v = [weakSelf inputToolBarStartPos]; - + if (pos < v || !view) { pos = v; } - + [weakSelf setToolbarBottomConstraintValue:pos animated:animated]; }; @@ -254,18 +253,18 @@ - (void)changeDataSource:(QMChatDataSource *)dataSource } switch (updateType) { - + case QMDataSourceActionTypeAdd: - [self.collectionView insertItemsAtIndexPaths:indexPaths]; - break; - + [self.collectionView insertItemsAtIndexPaths:indexPaths]; + break; + case QMDataSourceActionTypeUpdate: - [self.collectionView reloadItemsAtIndexPaths:indexPaths]; - break; - + [self.collectionView reloadItemsAtIndexPaths:indexPaths]; + break; + case QMDataSourceActionTypeRemove: - [self.collectionView deleteItemsAtIndexPaths:indexPaths]; - break; + [self.collectionView deleteItemsAtIndexPaths:indexPaths]; + break; } }; @@ -282,7 +281,7 @@ - (void)chatDataSource:(QMChatDataSource *)chatDataSource willBeChangedWithMessa #pragma mark - View lifecycle - (NSUInteger)inputToolBarStartPos { - + return 0; } @@ -794,12 +793,6 @@ - (void)setToolbarBottomConstraintValue:(CGFloat)constraintValue animated:(BOOL) self.toolbarBottomLayoutGuide.constant = constraintValue; if (animated) { - self.navigationController.interactivePopGestureRecognizer.enabled = NO; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - - self.navigationController.interactivePopGestureRecognizer.enabled = YES; - }); - [self.view layoutIfNeeded]; } } @@ -950,10 +943,10 @@ - (void)checkAuthorizationStatusWithCompletion:(void (^)(BOOL granted))completio switch (status) { case PHAuthorizationStatusAuthorized: - if (completion) { - completion(YES); - } - break; + if (completion) { + completion(YES); + } + break; case PHAuthorizationStatusNotDetermined: { [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus authorizationStatus) @@ -967,10 +960,10 @@ - (void)checkAuthorizationStatusWithCompletion:(void (^)(BOOL granted))completio break; } default: - if (completion) { - completion(NO); - } - break; + if (completion) { + completion(NO); + } + break; } } }