From 299cd4cd01b33ae5d6a4982638a1e7e3e1a66869 Mon Sep 17 00:00:00 2001 From: Kyle Corbitt Date: Fri, 11 Mar 2016 12:23:53 -0800 Subject: [PATCH] Fix empty ScrollView warnings Summary:Currently, an empty `` on iOS always throws the warning "Sticky header index 0 was outside the range {0, 0}". This is because the error-reporting code relies on the assumption that `stickyHeaderIndices` exists, and when it doesn't the error check thinks there's an index when there really isn't. Note that this only changes error reporting and won't affect apps out of debug mode. **Test plan** I created a sample app and included an empty ``. Without this change the "Sticky header..." warning was displayed on every run through. With this change implemented, the warning went away. Closes https://github.com/facebook/react-native/pull/6417 Differential Revision: D3042178 Pulled By: nicklockwood fb-gh-sync-id: 7afefd428a5fcb03867bcb69e46c46fe1ae9151e shipit-source-id: 7afefd428a5fcb03867bcb69e46c46fe1ae9151e --- React/Views/RCTScrollView.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/React/Views/RCTScrollView.m b/React/Views/RCTScrollView.m index 4df421f91..c38e6ed4c 100644 --- a/React/Views/RCTScrollView.m +++ b/React/Views/RCTScrollView.m @@ -838,7 +838,10 @@ RCT_SCROLL_EVENT_HANDLER(scrollViewDidZoom, RCTScrollEventTypeMove) if (RCT_DEBUG) { // Validate that sticky headers are not out of range. NSUInteger subviewCount = _scrollView.contentView.reactSubviews.count; - NSUInteger lastIndex = _scrollView.stickyHeaderIndices.lastIndex; + 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);