From e18d1394e4c3b203191c1a047cf6f5ac018f46f6 Mon Sep 17 00:00:00 2001 From: rewcraig Date: Sat, 29 Apr 2017 15:54:00 -0700 Subject: [PATCH] Fix issue with swipe to delete cell gesture. (#46) Ensure superclass scroll view delegate methods are called when the scroll view parameter is not the current ASTableView. --- Source/ASTableView.mm | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Source/ASTableView.mm b/Source/ASTableView.mm index 40193ce20d..27411e95e3 100644 --- a/Source/ASTableView.mm +++ b/Source/ASTableView.mm @@ -51,6 +51,26 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; return __val; \ } +#define UITABLEVIEW_RESPONDS_TO_SELECTOR() \ + ({ \ + static BOOL superResponds; \ + static dispatch_once_t onceToken; \ + dispatch_once(&onceToken, ^{ \ + superResponds = [UITableView instancesRespondToSelector:_cmd]; \ + }); \ + superResponds; \ + }) + +@interface UITableView (ScrollViewDelegate) + +- (void)scrollViewDidScroll:(UIScrollView *)scrollView; +- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView; +- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView; +- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset; +- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate; + +@end + #pragma mark - #pragma mark ASCellNode<->UITableViewCell bridging. @@ -1173,6 +1193,10 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; - (void)scrollViewDidScroll:(UIScrollView *)scrollView { + if (scrollView != self && UITABLEVIEW_RESPONDS_TO_SELECTOR()) { + [super scrollViewDidScroll:scrollView]; + return; + } // If a scroll happenes the current range mode needs to go to full ASInterfaceState interfaceState = [self interfaceStateForRangeController:_rangeController]; if (ASInterfaceStateIncludesVisible(interfaceState)) { @@ -1192,6 +1216,10 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset { + if (scrollView != self && UITABLEVIEW_RESPONDS_TO_SELECTOR()) { + [super scrollViewWillEndDragging:scrollView withVelocity:velocity targetContentOffset:targetContentOffset]; + return; + } CGPoint contentOffset = scrollView.contentOffset; _deceleratingVelocity = CGPointMake( contentOffset.x - ((targetContentOffset != NULL) ? targetContentOffset->x : 0), @@ -1210,6 +1238,10 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { + if (scrollView != self && UITABLEVIEW_RESPONDS_TO_SELECTOR()) { + [super scrollViewDidEndDecelerating:scrollView]; + return; + } _deceleratingVelocity = CGPointZero; if (_asyncDelegateFlags.scrollViewDidEndDecelerating) { @@ -1219,6 +1251,10 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { + if (scrollView != self && UITABLEVIEW_RESPONDS_TO_SELECTOR()) { + [super scrollViewWillBeginDragging:scrollView]; + return; + } for (_ASTableViewCell *tableViewCell in _cellsForVisibilityUpdates) { [[tableViewCell node] cellNodeVisibilityEvent:ASCellNodeVisibilityEventWillBeginDragging inScrollView:scrollView @@ -1231,6 +1267,10 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { + if (scrollView != self && UITABLEVIEW_RESPONDS_TO_SELECTOR()) { + [super scrollViewDidEndDragging:scrollView willDecelerate:decelerate]; + return; + } for (_ASTableViewCell *tableViewCell in _cellsForVisibilityUpdates) { [[tableViewCell node] cellNodeVisibilityEvent:ASCellNodeVisibilityEventDidEndDragging inScrollView:scrollView