From b82ea9d1f774e4cd7ed06804313b59e7eda5a666 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Sun, 5 Mar 2017 14:01:05 -0800 Subject: [PATCH] Remove unused native iOS sticky headers implementation Summary: Remove the native iOS sticky headers implementation that has been replaced by the js Animated one. Also remove a line in JS that made sure we passed null to native so it did not use the native implementation. **Test plan** Made sure there were no more mentions of sticky / header in native ScrollView related code. Tested that sticky headers still work :o Closes https://github.com/facebook/react-native/pull/12696 Differential Revision: D4657391 Pulled By: ericvicenti fbshipit-source-id: 16324a45ca4ce5cd143293c61394a0fa7ad0c4a1 --- Libraries/Components/ScrollView/ScrollView.js | 1 - React/Views/RCTScrollView.h | 1 - React/Views/RCTScrollView.m | 134 +----------------- React/Views/RCTScrollViewManager.m | 1 - 4 files changed, 1 insertion(+), 136 deletions(-) diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index a7b88931626762..dc49511bcde916 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -662,7 +662,6 @@ const ScrollView = React.createClass({ scrollEventThrottle: hasStickyHeaders ? 1 : this.props.scrollEventThrottle, sendMomentumEvents: (this.props.onMomentumScrollBegin || this.props.onMomentumScrollEnd) ? true : false, - stickyHeaderIndices: null, }; const { decelerationRate } = this.props; diff --git a/React/Views/RCTScrollView.h b/React/Views/RCTScrollView.h index 5d9f1b6942261a..4f399461194709 100644 --- a/React/Views/RCTScrollView.h +++ b/React/Views/RCTScrollView.h @@ -46,7 +46,6 @@ @property (nonatomic, assign) BOOL centerContent; @property (nonatomic, assign) int snapToInterval; @property (nonatomic, copy) NSString *snapToAlignment; -@property (nonatomic, copy) NSIndexSet *stickyHeaderIndices; // NOTE: currently these event props are only declared so we can export the // event names to JS - we don't call the blocks directly because scroll events diff --git a/React/Views/RCTScrollView.m b/React/Views/RCTScrollView.m index 3115b91425bdde..3c73d2e8409a9e 100644 --- a/React/Views/RCTScrollView.m +++ b/React/Views/RCTScrollView.m @@ -23,9 +23,6 @@ #import "RCTRefreshControl.h" #endif -CGFloat const ZINDEX_DEFAULT = 0; -CGFloat const ZINDEX_STICKY_HEADER = 50; - @interface RCTScrollEvent : NSObject - (instancetype)initWithEventName:(NSString *)eventName @@ -137,11 +134,10 @@ - (NSArray *)arguments /** * Include a custom scroll view subclass because we want to limit certain * default UIKit behaviors such as textFields automatically scrolling - * scroll views that contain them and support sticky headers. + * scroll views that contain them. */ @interface RCTCustomScrollView : UIScrollView -@property (nonatomic, copy) NSIndexSet *stickyHeaderIndices; @property (nonatomic, assign) BOOL centerContent; #if !TARGET_OS_TV @property (nonatomic, strong) RCTRefreshControl *rctRefreshControl; @@ -151,9 +147,6 @@ @interface RCTCustomScrollView : UIScrollView @implementation RCTCustomScrollView -{ - __weak UIView *_dockedHeaderView; -} - (instancetype)initWithFrame:(CGRect)frame { @@ -279,98 +272,6 @@ - (void)setContentOffset:(CGPoint)contentOffset super.contentOffset = contentOffset; } -- (void)dockClosestSectionHeader -{ - UIView *contentView = [self contentView]; - CGFloat scrollTop = self.bounds.origin.y + self.contentInset.top; - -#if !TARGET_OS_TV - // If the RefreshControl is refreshing, remove it's height so sticky headers are - // positioned properly when scrolling down while refreshing. - if (_rctRefreshControl != nil && _rctRefreshControl.refreshing) { - scrollTop -= _rctRefreshControl.frame.size.height; - } -#endif - - // Find the section headers that need to be docked - __block UIView *previousHeader = nil; - __block UIView *currentHeader = nil; - __block UIView *nextHeader = nil; - NSUInteger subviewCount = contentView.reactSubviews.count; - [_stickyHeaderIndices enumerateIndexesWithOptions:0 usingBlock: - ^(NSUInteger idx, BOOL *stop) { - - // If the subviews are out of sync with the sticky header indices don't - // do anything. - if (idx >= subviewCount) { - *stop = YES; - return; - } - - UIView *header = contentView.reactSubviews[idx]; - - // If nextHeader not yet found, search for docked headers - if (!nextHeader) { - CGFloat height = header.bounds.size.height; - CGFloat top = header.center.y - height * header.layer.anchorPoint.y; - if (top > scrollTop) { - nextHeader = header; - } else { - previousHeader = currentHeader; - currentHeader = header; - } - } - - // Reset transforms for header views - header.transform = CGAffineTransformIdentity; - header.layer.zPosition = ZINDEX_DEFAULT; - - }]; - - // If no docked header, bail out - if (!currentHeader) { - return; - } - - // Adjust current header to hug the top of the screen - CGFloat currentFrameHeight = currentHeader.bounds.size.height; - CGFloat currentFrameTop = currentHeader.center.y - currentFrameHeight * currentHeader.layer.anchorPoint.y; - CGFloat yOffset = scrollTop - currentFrameTop; - if (nextHeader) { - // The next header nudges the current header out of the way when it reaches - // the top of the screen - CGFloat nextFrameHeight = nextHeader.bounds.size.height; - CGFloat nextFrameTop = nextHeader.center.y - nextFrameHeight * nextHeader.layer.anchorPoint.y; - CGFloat overlap = currentFrameHeight - (nextFrameTop - scrollTop); - yOffset -= MAX(0, overlap); - } - currentHeader.transform = CGAffineTransformMakeTranslation(0, yOffset); - currentHeader.layer.zPosition = ZINDEX_STICKY_HEADER; - _dockedHeaderView = currentHeader; - - if (previousHeader) { - // The previous header sits right above the currentHeader's initial position - // so it scrolls away nicely once the currentHeader has locked into place - CGFloat previousFrameHeight = previousHeader.bounds.size.height; - CGFloat targetCenter = currentFrameTop - previousFrameHeight * (1.0 - previousHeader.layer.anchorPoint.y); - yOffset = targetCenter - previousHeader.center.y; - previousHeader.transform = CGAffineTransformMakeTranslation(0, yOffset); - previousHeader.layer.zPosition = ZINDEX_STICKY_HEADER; - } -} - -- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event -{ - if (_dockedHeaderView && [self pointInside:point withEvent:event]) { - CGPoint convertedPoint = [_dockedHeaderView convertPoint:point fromView:self]; - UIView *hitView = [_dockedHeaderView hitTest:convertedPoint withEvent:event]; - if (hitView) { - return hitView; - } - } - return [super hitTest:point withEvent:event]; -} - static inline BOOL isRectInvalid(CGRect rect) { return isnan(rect.origin.x) || isinf(rect.origin.x) || isnan(rect.origin.y) || isinf(rect.origin.y) || @@ -522,18 +423,6 @@ - (void)setCenterContent:(BOOL)centerContent _scrollView.centerContent = centerContent; } -- (NSIndexSet *)stickyHeaderIndices -{ - return _scrollView.stickyHeaderIndices; -} - -- (void)setStickyHeaderIndices:(NSIndexSet *)headerIndices -{ - RCTAssert(_scrollView.contentSize.width <= self.frame.size.width, - @"sticky headers are not supported with horizontal scrolled views"); - _scrollView.stickyHeaderIndices = headerIndices; -} - - (void)setClipsToBounds:(BOOL)clipsToBounds { super.clipsToBounds = clipsToBounds; @@ -697,7 +586,6 @@ - (void)removeScrollListener:(NSObject *)scrollListener - (void)scrollViewDidScroll:(UIScrollView *)scrollView { - [_scrollView dockClosestSectionHeader]; [self updateClippedSubviews]; NSTimeInterval now = CACurrentMediaTime(); @@ -960,26 +848,6 @@ - (void)reactBridgeDidFinishTransaction _scrollView.contentSize = contentSize; _scrollView.contentOffset = newOffset; } - - if (RCT_DEBUG) { - // Validate that sticky headers are not out of range. - NSUInteger subviewCount = _scrollView.contentView.reactSubviews.count; - NSUInteger lastIndex = NSNotFound; - if (_scrollView.stickyHeaderIndices != nil) { - lastIndex = _scrollView.stickyHeaderIndices.lastIndex; - } - if (lastIndex != NSNotFound && lastIndex >= subviewCount) { - RCTLogWarn(@"Sticky header index %zd was outside the range {0, %zd}", - lastIndex, subviewCount); - } - } -} - -- (void)didSetProps:(NSArray *)changedProps -{ - if ([changedProps containsObject:@"stickyHeaderIndices"]) { - [_scrollView dockClosestSectionHeader]; - } } // Note: setting several properties of UIScrollView has the effect of diff --git a/React/Views/RCTScrollViewManager.m b/React/Views/RCTScrollViewManager.m index 62f5a41abf8cb6..7b3db9fad22cf1 100644 --- a/React/Views/RCTScrollViewManager.m +++ b/React/Views/RCTScrollViewManager.m @@ -67,7 +67,6 @@ - (UIView *)view #endif RCT_EXPORT_VIEW_PROPERTY(showsHorizontalScrollIndicator, BOOL) RCT_EXPORT_VIEW_PROPERTY(showsVerticalScrollIndicator, BOOL) -RCT_EXPORT_VIEW_PROPERTY(stickyHeaderIndices, NSIndexSet) RCT_EXPORT_VIEW_PROPERTY(scrollEventThrottle, NSTimeInterval) RCT_EXPORT_VIEW_PROPERTY(zoomScale, CGFloat) RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets)